What is a daemon thread?

Source: Internet
Author: User

"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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.