Java Reference
In-Depth Information
BlockingQueue
and the logger thread writes it out. This is a multiple-producer, single-
consumer design: any activity calling
log
is acting as a producer, and the background logger
thread is the consumer. If the logger thread falls behind, the
BlockingQueue
eventually
blocks the producers until the logger thread catches up.
Listing 7.13. Producer-Consumer Logging Service with No Shutdown Support.
For a service like
LogWriter
to be useful in production, we need a way to terminate the
logger thread so it does not prevent the JVM from shutting down normally. Stopping the log-