Java Reference
In-Depth Information
ting down, since any work submitted prior to submitting the poison pill will be retrieved be-
fore the pill; producers should not submit any work after putting a poison pill on the queue.
IndexingService in Listings 7.17 , 7.18 , and 7.19 shows a single-producer, single-con-
sumer version of the desktop search example from Listing 5.8 on page 91 that uses a poison
pill to shut down the service.
Listing 7.17. Shutdown with Poison Pill.
Poison pills work only when the number of producers and consumers is known. The approach
in IndexingService can be extended tomultiple producers by having each producer
place a pill on the queue and having the consumer stop only when it receives N producers pills.
It can be extended to multiple consumers by having each producer place N consumers pills on
the queue, though this can get unwieldy with large numbers of producers and consumers.
Poison pills work reliably only with unbounded queues.
Search WWH ::




Custom Search