A single normal Java thread referred to as a "waiter" thread is used to prevent
premature exit of the Java Virtual Machine during the shutdown process of the server
application by waiting for any daemon threads in the JVM to complete execution.
Using this mechanism, any daemon thread flagged by the application runs to completion
before the JVM is allowed to exit. Once all flagged daemon threads exit, the waiter
thread exits and allows the server application to properly terminate. The waiter
thread uses an efficient mechanism to maintain a queue of threads. When a daemon
thread is flagged, it is simply appended to the end of the queue. The waiter thread
waits for the first thread in the queue to complete. Once the first thread in the
queue completes, it is removed from the queue. At this point, the queue is searched
for any other inactive threads and those threads are also removed from the queue.
This allows the waiter thread to efficiently manage the queue and keep the memory
and resource requirements to a minimum.