Method blockingPut and the Producer Thread
When the Producer
thread’s run
method invokes synchronized
method blockingPut
, the thread implicitly attempts to acquire the SynchronizedBuffer
object’s monitor lock. If the monitor lock is available, the Producer
thread implicitly acquires the lock. Then the loop at lines 14–20 first determines whether occupied
is true
. If so, buffer
is full and we want to wait until the buffer is empty, so line 17 outputs a message indicating that the Producer
thread is trying to write a value, and line 18 invokes method displayState
(lines 57–61) to output another message indicating that buffer
is full and that the Producer
thread is waiting until there’s space. Line 19 invokes method wait
(inherited from Object ...
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.