... 13–14 create two Condition
s using Lock
method newCondition
:
-
Condition
canWrite
contains a queue for aProducer
thread waiting while the buffer is full (i.e., there’s data in the buffer that theConsumer
has not read yet). If the buffer is full, theProducer
calls methodawait
on thisCondition
. When theConsumer
reads data from a full buffer, it calls methodsignal
on thisCondition
. -
Condition
canRead
contains a queue for aConsumer
thread waiting while the buffer is empty (i.e., there’s no data in the buffer for theConsumer
to read). If the buffer is empty, theConsumer
calls methodawait
on thisCondition
. When theProducer
writes to the empty buffer, it calls methodsignal
on thisCondition
.
The int
variable buffer
(line 16) holds the shared ...
Get Java How to Program, Early 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.