java 线程优先级的设置

2022-02-22 00:00:00 优先级 线程 设置
package Process;

public class Test { 
    public static void main(String[] args) { 
        System.out.println(Thread.MAX_PRIORITY);
        System.out.println(Thread.MIN_PRIORITY);
        System.out.println(Thread.NORM_PRIORITY);
        System.out.println(Thread.currentThread().getName()+"的默认优先级为"+Thread.currentThread().getPriority());
        Thread.currentThread().setPriority(10);
        System.out.println(Thread.currentThread().getName()+"的优先级被设置为"+Thread.currentThread().getPriority());
        Thread t = new Thread(new A());
        t.start();
        t.setName("Aa1");
    }
    static class A implements Runnable{ 

        @Override
        public void run() { 
            System.out.println(Thread.currentThread().getName()+"的默认优先级为"+Thread.currentThread().getPriority());
        }
    }
}

    原文作者:#眼镜&
    原文地址: https://blog.csdn.net/qq_45858803/article/details/121708238
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。

相关文章