Java Reference
In-Depth Information
This method simply calls wait( ) . This call won't return until changeColor( ) ex-
ecutes a call to notify( ) . Thus, waitForChange( ) won't return until the color has
changed.
7 . Finally, add the methods getColor( ) , which returns the current light color, and can-
cel( ) , which stops the traffic light thread by setting stop to true . These methods are
shown here:
8 . Here is all the code assembled into a complete program that demonstrates the traffic
light:
Search WWH ::




Custom Search