Bridge control applet
The source.
Applet blues
You may have some problems if you run this with Netscape 3.0B5 for Windows 95.
It appears that some functions in the VM
are not allowed. If you are interested in details, e-mail me at
david.ripps@javaworld.com.
There are also some issues with the Internet Explorer Beta.
Applet explanation
This bridge control applet was adopted from An Implementation Guide to
Real-time Programming, Prentice-Hall, ISBN 0-13-451873-X (1990).
In this applet there are four threads:
- The main applet thread that first performs initialization for the
entire applet, creates and starts the three real-time (embedded) threads,
and then becomes the roadway simulation that supplies the "real
world" in which the real-time threads operate.
- The
CaptureData interrupt thread that waits for
changes in the roadway sensors. The thread runs at a very high
priority. When the thread resumes, it creates a new
VehicleData buffer, stores the sensor data within that
buffer, and adds the buffer to a chain of similar buffers that is
maintained via a monitor. CaptureData then waits for the
next interrupt. The interrupting agent is the main applet thread. This
method of starting CaptureData simulates the generation
of a hardware interrupt that is handled by a thread
(CaptureData in this case).
- The
DigestData thread that remains in a loop waiting
for a VehicleData buffer. When a buffer becomes
available, DigestData uses any changes in the bridge
sensors (one at each end of the bridge) to maintain a tally of the
number of vehicles that are currently on the bridge. It also maintains
the current status of a pair of roadway sensors that note when there
are vehicles approaching the left-bound and right-bound entries to the
bridge. The thread runs at a middle level of priority. The on-bridge
tally (and the direction of bridge traffic) are protected by a monitor
that guarantees that only one thread at a time can examine or use that
information. The direction of bridge traffic is set by the
ControlLights thread but is needed by
DigestData to determine if a bridge sensor pulse means a
vehicle entering or leaving the bridge.
- The
ControlLights thread that performs the actual
control of the lights that block left-bound and right-bound traffic
from attempting to cross the single-lane bridge at the same time. The
thread runs at a low priority. It uses the on-bridge tally and
car-waiting sensor information maintained by DigestData.