import java.util.*;
/**
* <p>Title: 提高線程優先級</p>
* <p>Description: 通過修改線程的優先級,是線程獲得優先處理。</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Filename: upPRIThread.java</p>
* @version 1.0
*/
public class upPRIThread {
//主方法
public static void main(String[] args) throws Exception {
Thread1 t1 = new Thread1();
t1.start();
Thread2 t2 = new Thread2();
t2.start();
t1.setPriority(Thread.MIN_PRIORITY);
t2.setPriority(Thread.MIN_PRIORITY);
new Thread().sleep(105);
t2.setPriority(Thread.MAX_PRIORITY);
new Thread().sleep(10500);
}
//類說明:線程1,不更改優先級
static class Thread1 extends Thread {
public void run(){
while(true){
try {
Thread.sleep(100);
}
catch (Exception e){
e.printStackTrace();
}
System.out.println("我是線程111");
}
}
}
//類說明:線程2,提高優先級
static class Thread2 extends Thread {public void run(){
while(true){
try {
Thread.sleep(100);
}
catch (Exception e){
e.printStackTrace();
}
System.out.println("我是線程222.........................");
}
}
}
}