Creation and operation of daemon threads

Source: Internet
Author: User

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

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.