Class BlockingBufferTest

Class BlockingBufferTest (Fig. 23.15) contains the main method that launches the application. Line 13 creates an ExecutorService, and line 16 creates a BlockingBuffer object and assigns its reference to the Buffer variable sharedLocation. Lines 18–19 execute the Producer and Consumer Runnables. Line 21 calls method shutdown to end the application when the threads finish executing the Producer and Consumer tasks and line 22 waits for the scheduled tasks to complete.

 1   // Fig. 23.15: BlockingBufferTest.java 2   // Two threads manipulating a blocking buffer that properly 3   // implements the producer/consumer relationship. 4   import java.util.concurrent.ExecutorService; 5   import java.util.concurrent.Executors; ...

Get Java™ How To Program (Early Objects), Tenth 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.