其他分享
首页 > 其他分享> > 线程优先级Priority

线程优先级Priority

作者:互联网

public class TestThreadPriority {

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

MyPriority myPriority = new MyPriority();
Thread thread1 = new Thread(myPriority,"小明");
Thread thread2 = new Thread(myPriority,"小红");
Thread thread3 = new Thread(myPriority,"小黄");
Thread thread4 = new Thread(myPriority,"小绿");

thread1.setPriority(Thread.MAX_PRIORITY);
thread1.start();
thread2.setPriority(Thread.MIN_PRIORITY);
thread2.start();
thread3.setPriority(5);
thread3.start();
thread4.setPriority(2);
thread4.start();
}
}
class MyPriority implements Runnable{
@Override
public void run() {
System.out.println(Thread.currentThread().getName()+"-->的优先级是"+Thread.currentThread().getPriority());
}
}

标签:myPriority,优先级,currentThread,Thread,Priority,start,setPriority,线程,new
来源: https://www.cnblogs.com/peanutist/p/14496742.html