Testing Class CircularBuffer

Class CircularBufferTest (Fig. 23.19) contains the main method that launches the application. Line 12 creates the ExecutorService, and line 15 creates a CircularBuffer object and assigns its reference to CircularBuffer variable sharedLocation. Line 18 invokes the CircularBuffer’s displayState method to show the initial state of the buffer. Lines 21–22 execute the Producer and Consumer tasks. Line 24 calls method shutdown to end the application when the threads complete the Producer and Consumer tasks and line 25 waits for the tasks to complete.

 1   // Fig. 23.19: CircularBufferTest.java 2   // Producer and Consumer threads correctly manipulating a circular buffer. 3   import java.util.concurrent.ExecutorService; ...

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.