码迷,mamicode.com
首页 > 编程语言 > 详细

多线程优先级

时间:2014-11-10 17:32:14      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:io   ar   sp   on   art   bs   ad   as   new   

class user extends Thread {
private Thread fth;

user(String name, Thread fth) {
super(name);
this.fth = fth;
}

public void run() {
System.out.println(this.getName());
try {
sleep(2000);
} catch (Exception e) {
// TODO: handle exception
throw new RuntimeException(e);
}
if (fth != null) {
try {
fth.join();

} catch (Exception e) {

}
System.out.println("NAME:" + this.getName() + "Bye");

}
}


}

 

 

 

 

 

 

 

 

 

class MT{
public static void main(String[] args) throws InterruptedException {
user u1=new user("1",null);
user u2=new user("2",u1);
user u3=new user("3",u2);
user u4=new user("4",u3);
u1.setPriority(Thread.MAX_PRIORITY);
u2.setPriority(Thread.MAX_PRIORITY-1);
u3.setPriority(Thread.MAX_PRIORITY-2);
u4.setPriority(Thread.MAX_PRIORITY-3);
u1.start();
u2.start();
u3.start();
u4.start();

}
}

 

多线程优先级

标签:io   ar   sp   on   art   bs   ad   as   new   

原文地址:http://www.cnblogs.com/sunshine-in/p/4087537.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!