Testing Class SynchronizedBuffer
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. ...
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.