February 2014
Beginner
1248 pages
62h 25m
English
Class UnsynchronizedBuffer (Fig. 23.12) implements interface Buffer (line 4), but does not synchronize access to the buffer’s state—we purposely do this to demonstrate the problems that occur when multiple threads access shared mutable data in without synchronization. Line 6 declares instance variable buffer and initializes it to -1. This value is used to demonstrate the case in which the Consumer attempts to consume a value before the Producer ever places a value in buffer. Again, methods blockingPut (lines 9–13) and blockingGet (lines 16–20) do not synchronize access to the buffer instance variable. Method blockingPut simply assigns its argument to buffer (line 12), and method ...
Read now
Unlock full access