in theJavaThere are two types of threads in: User thread(User Thread), daemon Threads(Daemon Thread).
A daemon thread is a thread that provides a generic service in the background while the program is running, such as a garbage collection thread that is a competent guardian, and that thread is not an integral part of the program. Therefore, when all non-daemon threads end, the program terminates and kills all the daemon threads in the process. Conversely, the program will not terminate as long as any non-daemon threads are still running.
The only difference between the user thread and the daemon is that the virtual machine leaves: If the user thread is all out of operation, only the daemon thread is present, and the virtual machine exits.
Converting a thread to a daemon can be done by calling thread setdaemon (True) method to achieve. There are a few things to keep in mind when using a daemon:
(1) Thread.setdaemon (true) must be in the thread.start ()
illegalthreadstateexception exception. You cannot set a running regular thread as a daemon thread.
(2) in daemon The new thread generated in the thread is also daemon the.
(3) the daemon should never access an intrinsic resource, such as a file or a database, because it will be interrupted at any time, even in the middle of an operation.
Java concurrent Programming--Daemon threads (Daemon thread)