"What is a daemon thread?" "
Java provides two types of threads: the daemon thread and the user thread.
Daemon Threads also known as the "service process" "Daemon thread" "Background thread", refers to a program running in the background to provide a common thread, this thread is not an integral part of the program. In layman's words, any daemon is a "Nanny" for all non-daemon threads throughout the JVM.
User Thread As with the daemon thread, the only difference is that if the user thread is all out of operation, only the daemon thread exists, the JVM also exits. Because when all non-daemons end, without the Guardian, the daemon will have no work to do, there is no need to continue to run the program, the program will be terminated, and will "kill" all the daemon thread. That is, the program does not terminate as long as any non-daemon threads are still running.
in the In the Java language, the daemon thread generally has a lower priority, it is not only provided internally by the JVM , and users can set their own daemon threads when writing programs, for example The method of setting a user thread as a daemon is to call the Setdaemon (True) method of the object before invoking the start () method , if the argument in the above parentheses is set to False, the user process mode is indicated.
It is important to note that when other threads are generated in one daemon thread, the newly generated threads are still the daemon thread by default, as are the user threads.
The garbage collector is a daemon thread.
What is a daemon thread?