In Java, there is a special thread called a daemon (daemon) thread. This thread has a low priority, and typically, when no other thread in the same application is running, the guard line friend run. When the daemon thread is the only thread running in the program, the JVM ends the program when the daemon executes.
Because of this feature, the daemon thread is often used as a service prompt for ordinary threads (also known as user threads) in the same program. They are usually infinite loops to wait for a service request or to execute a thread's task. They cannot do important work because it is impossible to know when the daemon will be able to get the CPU clock, and when no other thread is running, the daemon thread may end at any time. A typical daemon thread is the Java garbage collector (garbage Collector).
The sample program contains two threads: one is the user thread, it writes the event to a queue, and the other is the daemon, which manages the queue and is removed if the generated event exceeds 10 seconds.
--------------Keep writing-----------------------------tomorrow.
Creation and operation of daemon threads