Project Two Suggestions
A possible breakup of classes:
Bridge: It might minimally have these methods in addition
to any constructors.
-
runSimulation: You can call this from your main() method. It runs
a simulation by creating threads representing people trying to cross the
river. The simulation then waits for the people to finish and possibly
dumps some statistics at the end.
-
cross: This method causes a person thread to cross the bridge. It
should not take each person the same amount of time to cross the bridge.
This method returns when the "person gets to the other side of the river".
Until it returns, the thread that called it is blocked. A thread can call
this method while another thread is blocked in it, subject to the rules
described in the problem for crossing the bridge.
Note: The arrival of people at the bridge should be staggered. Your
solution should work no matter who comes to the bridge, what order they
come in, and how long they take to cross the bridge.
Person: It might minimally have these methods
in addition to any constructors.
-
run: Person implements the Runnable interface. The run method should
print a startup message, wait until it is safe to cross the river, cross
the river, and print a return message.
CrossingGuard: This represents the "monitor" class
(a Java class with synchronized methods) as the synchronization mechanism
for your solution. Create only one instance of this class, most likely
in main() and make sure that it can be referenced by the run method of
Person.
-
You will need to figure out the methods for this class.