February 2014
Beginner
1248 pages
62h 25m
English
Methods blockingGet and blockingPut are implemented similarly. When the Consumer thread’s run method invokes synchronized method blockingGet, the thread attempts to acquire the monitor lock on the SynchronizedBuffer object. If the lock is available, the Consumer thread acquires it. Then the while loop at lines 37–43 determines whether occupied is false. If so, the buffer is empty, so line 40 outputs a message indicating that the Consumer thread is trying to read a value, and line 41 invokes method displayState to output a message indicating that the buffer is empty and that the Consumer thread is waiting. Line 42 invokes method wait to place the thread that called method blockingGet (i.e., the Consumer ...
Read now
Unlock full access