1. Note
The type of thread (user thread or daemon thread) does not affect the priority of thread execution.
The type of thread, whether it is a daemon thread or a user thread, has no impact on the priority of program execution. When we adjust the priority to , the running results of the entire program are completely different.
2. Example
public class DaemonExample { private static final int count = 100000; public static void main(String[] args) throws InterruptedException { // 定义任务 Runnable runnable = new Runnable() { @Override public void run() { for (int i = 0; i < count; i++) { System.out.println("执行线程:" + Thread.currentThread().getName()); } } }; // 创建守护线程 t1 Thread t1 = new Thread(runnable, "t1"); // 设置为守护线程 t1.setDaemon(true); // 启动线程 t1.start(); // 创建用户线程 t2 Thread t2 = new Thread(runnable, "t2"); // 启动线程 t2.start(); } }
The above is the detailed content of What is the execution priority of java daemon thread?. For more information, please follow other related articles on the PHP Chinese website!