February 2014
Beginner
1248 pages
62h 25m
English
Class SynchronizedBuffer contains fields buffer (line 6) and occupied (line 7)—you must synchronize access to both fields to ensure that class SynchronizedBuffer is thread safe. Methods blockingPut (lines 10–31) and blockingGet (lines 34–54) are declared as synchronized—only one thread can call either of these methods at a time on a particular SynchronizedBuffer object. Field occupied is used to determine whether it’s the Producer’s or the Consumer’s turn to perform a task. This field is used in conditional expressions in both the blockingPut and blockingGet methods. If occupied is false, then buffer is empty, so the Consumer cannot read the value of buffer, but the Producer can place a value into ...
Read now
Unlock full access