我是靠谱客的博主 敏感钻石,这篇文章主要介绍线程十三—— 线程优先级权重的设置,现在分享给大家,希望可以做个参考。

注意  这里创建了五个线程 t1 t2 t3 t4 t5 五个线程 分别为每个线程设置优先级  

MAX_PRIORITY 最大优先级 十级 默认为五级 优先级 
MIN_PRIORITY 最小优先级 一级
package com.yyf.ThreadSleep;



// 设置线程优先级
public class TestPriority{


    public static void main(String[] args) {
        System.out.println (Thread.currentThread ().getName ()+"--->"+Thread.currentThread ().getPriority ());

        MyPriority myPriority = new MyPriority ();
        Thread t1 = new Thread (myPriority);
        Thread t2 = new Thread (myPriority);
        Thread t3 = new Thread (myPriority);
        Thread t4 = new Thread (myPriority);
        Thread t5 = new Thread (myPriority);



        t1.start ();

        t2.setPriority (Thread.MAX_PRIORITY);
        t2.start ();
        t3.setPriority (6);
        t3.start ();
        t4.setPriority (8);
        t4.start ();
        t5.setPriority (1);
        t5.start ();
    }


}
class  MyPriority implements Runnable{

    @Override
    public void run() {
        System.out.println (Thread.currentThread ().getName ()+"--->"+Thread.currentThread ().getPriority ());
    }
}

最后

以上就是敏感钻石最近收集整理的关于线程十三—— 线程优先级权重的设置的全部内容,更多相关线程十三——内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(132)

评论列表共有 0 条评论

立即
投稿
返回
顶部