Class SharedBufferTest
In class SharedBufferTest (Fig. 23.13), line 12 creates an ExecutorService to execute the Producer and Consumer Runnables. Line 15 creates an UnsynchronizedBuffer and assigns it to Buffer variable sharedLocation. This object stores the data that the Producer and Consumer threads will share. Lines 24–25 create and execute the Producer and Consumer. The Producer and Consumer constructors are each passed the same Buffer object (sharedLocation), so each object refers to the same Buffer. These lines also implicitly launch the threads and call each Runnable’s run method. Finally, line 27 calls method shutdown so that the application can terminate when the threads executing the Producer and Consumer complete their tasks and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access