Class SharedBufferTest
In class SharedBufferTest
(Fig. 23.13), line 12 creates an ExecutorService
to execute the Producer
and Consumer Runnable
s. 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 ...
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.