女鬼鬼门关投胎电影:XP系统是不是不支持线程的优先级别

来源:百度文库 编辑:高校问答 时间:2024/05/07 12:30:58
我刚学JAVA,有一个例题怎么做都和书上的结果不一样,是关于线程的优先级别:高手请看:
class cliker implements Runnable{
double k=0;
Thread t;
private volatile boolean running=true;
cliker(int p){
t=new Thread(this);
t.setPriority(p);
}
public void run(){
while(running){
k++;

}
}
public void stop(){
running=false;
}
public void start(){
t.start();
}
}

class mymain{
public static void main(String[] args){
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
cliker hi=new cliker(Thread.NORM_PRIORITY+2);
cliker lo=new cliker(Thread.NORM_PRIORITY-2);

hi.start();
lo.start();

try{
Thread.sleep(100);
}
catch(Exception e){
System.out.println("main Thread is interrupted!");
}
hi.stop();
lo.stop();

try{
hi.t.join();
lo.t.join();
}
catch(InterruptedException e){
System.out.println("InterruptedException is cautch!");
}
System.out.println(hi.k);
System.out.println(hi.k);
}
}

出来的结果两个K都是一样的?