/**
* Created by Leon on 2017/5/22.
* 线程优先级用数字表示,范围1到10,缺省为5
* Thread.MIN_PRIORITY=1
* Thread.MAX_PRIORITY=10
* Thread.NORM_PRIORITY=5
* int getPriority();//获得对象优先级
* void setPriority(int newPriority);//设置对象优先级
*/
public class TestPriority
{
public static void main(String[] args)
{
Thread t1=new Thread(new T1());
Thread t2=new Thread(new T2());
t1.setPriority(Thread.NORM_PRIORITY+3);
t1.start();
t2.start();
}
}
class T1 implements Runnable
{
public void run()
{
for (int i=0;i<1000;i++)
{
System.out.println("T1:"+i);
}
}
}
class T2 implements Runnable
{
public void run()
{
for (int i=0;i<1000;i++)
{
System.out.println("T2:"+i);
}
}
}
Java线程优先级
最新推荐文章于 2021-11-17 20:52:04 发布