... buffer is empty, so line 15 outputs a message indicating that the Producer thread is trying to write a value, and line 16 invokes method displayState (lines 54–56) to output another message indicating that buffer is full and that the Producer thread is waiting until there’s space. Line 17 invokes method wait (inherited from Object by SynchronizedBuffer) to place the thread that called method blockingPut (i.e., the Producer thread) in the waiting state for the SynchronizedBuffer object. The call to wait causes the calling thread to implicitly release the lock on the SynchronizedBuffer object. This is important because the thread cannot currently perform its task and because other threads (in this case, the Consumer) should be allowed to access the object ...

Get Java How To Program, Late Objects, 11th 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.