Three. Thread Priority and Daemon

Source: Internet
Author: User
1. Priority of Threads

In the operating system, threads can prioritize, high-priority threads get more CPU resources, and are the tasks in the higher-priority thread objects that the CPU prioritizes.

Setting the thread priority helps the thread planner determine which thread will be selected for priority execution next time.

Set the priority using the SetPriority () method.

The inheritance of thread precedence

The precedence of a thread in Java is inherited, such as a start B, and the priority of B is the same as a.

Precedence is rule-

Although you can set the priority of a thread by using the SetPriority () method, you do not see the effect of setting the priority level

Thread 2:

High-priority threads are always executed mostly first, but not for high-priority threads. Do not assume that the mythread thread is called by the main thread, and that the result is completely MyThread1 priority is 10.

When the priority of a thread varies greatly, the order in which the code is called does not have to be done first.

Precedence has randomness

Daemon process

There are two kinds of threads in a Java thread, one is a user thread and one is a daemon thread.

A daemon thread is a special thread that automatically destroys a daemon thread when there is no non-daemon thread in the thread. A typical daemon thread is a garbage collection thread. Any daemon thread is the "nanny" of all non-daemons in the entire JVM, as long as any non-daemon thread in the current JVM instance is not over, the daemon is working, and the Guardian thread friend with the JVM as soon as the last non-daemon thread ends.

Three. Thread Priority and Daemon

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.