Design Patterns Java™ Workbook

(Michael S) #1
Chapter 26. Introducing Extensions

Figure 26.3. These classes collaborate to produce the bin-stacking application.

This application depends on the monitors that Java supplies to every object. The wait()
method relinquishes a thread's possession of an object's monitor and makes the thread wait to
get it back. The notify() method wakes up a thread that will obtain the monitor when it
becomes available. Either of these methods can execute only in a thread that has the monitor.
One way to obtain an object's monitor is to execute a synchronized instance method of
that object. This is the technique that the BinStack class uses:

Free download pdf