package thead;
public class ThreadPriorityDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
ThreadPriority tp1=new ThreadPriority();
ThreadPriority tp2=new ThreadPriority();
ThreadPriority tp3=new ThreadPriority();
tp1.setName("糖果");
tp2.setName("冰淇凌");
tp3.setName("点心");
tp1.setPriority(10);
tp2.setPriority(5);
tp3.setPriority(1);
//设置线程的优先级,优先级范围:1-10数字越大优先级越高
// System.out.println(Thread.MAX_PRIORITY);//10
// System.out.println(Thread.MIN_PRIORITY);//1
// System.out.println(Thread.NORM_PRIORITY);//5
tp1.start();
tp2.start();
tp3.start();
}
}
package thead;
public class ThreadPriority extends Thread {
@Override
public void run() {
for (int i = 0; i < 100; i++) {
System.out.println(getName() + i);
}
}
}
自学线程之优先级(3)
最新推荐文章于 2020-12-30 05:34:12 发布