Java Reference
In-Depth Information
Figure 26.2 shows a Swing application—the ShowWaitAndNotify class in
com.oozinoz.applications —that models this situation.
Figure 26.2. The user of this application has pressed Load a fourth time, launching
a thread that will wait until the user clicks Unload.
With the application in the state that Figure 26.2 shows, a fourth, unseen bin awaits stacking.
Clicking Unload will remove a bin, letting the thread complete that is waiting to load a bin.
This will leave three bins in the stack and will reenable the Load button. Clicking Unload four
more times will clear the stack and then put the Unload button in a wait state, awaiting a bin
that it will immediately clear.
At the heart of an application is a BinStack class that uses wait() and notify() to
suspend threads that load or unload more bins than the stack can handle. Figure 26.3 shows
the application classes.
Search WWH ::




Custom Search