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.........................");
}
}
}
}
闽公网安备 35060202000074号