//测试线程的优先级
public class TestDemo1 {
//创建线程对象
public static void main(String[] args) {
//主线程默认优先级
System.out.println (Thread.currentThread ().getName ()+"-->"+Thread.currentThread ().getPriority ());
mypo mypo = new mypo ();
Thread t1 = new Thread (mypo);
Thread t2 = new Thread (mypo);
Thread t3 = new Thread (mypo);
Thread t4 = new Thread (mypo);
Thread t5 = new Thread (mypo);
Thread t6 = new Thread (mypo);
//先设置优先级,在启动
t1.start ();
t2.setPriority (1);
t2.start ();
t3.setPriority (4);
t3.start ();
t4.setPriority (Thread.MAX_PRIORITY);//MAX_PRIORITY=10
t4.start ();
t5.setPriority (8);
t5.start ();
t6.setPriority (7);
t6.start ();
}
}
class mypo implements Runnable{
@Override
public void run() {
System.out.println (Thread.currentThread ().getName ()+"-->"+Thread.currentThread ().getPriority ());
}
}
线程的优先级
最新推荐文章于 2024-01-08 00:15:00 发布