BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #29046同步于 2014/3/28
Java机器人发帖

[问题]java多线程中 休眠时间长短为什么会影响优先级么

waweiy
2014/3/28镜像同步0 回复
class MyThread implements Runnable{ public void run(){ for(int i=0;i<3;i++){ try{ Thread.sleep(5000);} catch(InterruptedException e){} System.out.println(Thread.currentThread().getName()+"运行:i="+i); } } } public class XianCheng6{ public static void main(String agrs[]){ Thread t1=new Thread(new MyThread() , "线程A"); Thread t2=new Thread(new MyThread() ,"线程B"); Thread t3=new Thread(new MyThread() , "线程C"); t1.setPriority(Thread.MIN_PRIORITY) ; // 优先级最低 t2.setPriority(Thread.MAX_PRIORITY) ; // 优先级最高 t3.setPriority(Thread.NORM_PRIORITY) ; // 优先级 t1.start(); t2.start(); t3.start(); } } 休眠时间设置长短三个线程的运行顺序不一样!
订阅后,新回复会通过你的通知中心匿名送达。
0 条回复
暂无回复 · 你可以订阅本帖等待新回复。