February 2014
Beginner
1248 pages
62h 25m
English
Class SharedBufferTest2 (Fig. 23.17) is similar to class SharedBufferTest (Fig. 23.13). SharedBufferTest2 contains method main (Fig. 23.17, lines 9–26), which launches the application. Line 12 creates an ExecutorService to run the Producer and Consumer tasks. Line 15 creates a SynchronizedBuffer object and assigns its reference to Buffer variable sharedLocation. This object stores the data that will be shared between the Producer and Consumer. Lines 17–18 display the column heads for the output. Lines 21–22 execute a Producer and a Consumer. Finally, line 24 calls method shutdown to end the application when the Producer and Consumer complete their tasks and line 25 waits for the scheduled tasks to complete. ...
Read now
Unlock full access