我是在vista系统下做的是实验,这是孙鑫老师的视频教程里的一个例子
public class MyThread extends Thread {
MyThread(){
super("MyThread");
}
public void run(){
while(true){
System.out.println(getName());
}
}
}
public class Main {
public static void main(String[] args){
MyThread mt=new MyThread();
mt.setDaemon(true);
mt.setPriority(Thread.MAX_PRIORITY);
mt.start();
int index=0;
while(true){
index++;
if(index>10)
break;
System.out.println(Thread.currentThread().getName());
}
}
}
给mt线程设置了最高的优先级,但是运行的时候也是先开始执行main线程,而且也不会出现时间片轮换,就是切换到mt线程运行时,就一直执行mt线程,不出现时间片轮换
是vista不支持时间片轮换??
public class MyThread extends Thread {
MyThread(){
super("MyThread");
}
public void run(){
while(true){
System.out.println(getName());
}
}
}
public class Main {
public static void main(String[] args){
MyThread mt=new MyThread();
mt.setDaemon(true);
mt.setPriority(Thread.MAX_PRIORITY);
mt.start();
int index=0;
while(true){
index++;
if(index>10)
break;
System.out.println(Thread.currentThread().getName());
}
}
}
给mt线程设置了最高的优先级,但是运行的时候也是先开始执行main线程,而且也不会出现时间片轮换,就是切换到mt线程运行时,就一直执行mt线程,不出现时间片轮换
是vista不支持时间片轮换??
我给你一段代码你运行一下:public class DaemonTest {
public static void main(String[] args) {
Thread t1=new MyThreadI();
Thread t2=new MyThreadI();
t1.setName("T1");
t2.setName("T2");
t1.setPriority(9);
t2.setPriority(1);
t2.setDaemon(true);
t1.start();
t2.start();
}
}
class MyThreadI extends Thread{
int i=0;
public void run(){
for(i=0;i<100;i++){
for(int j=0;j<10000000;j++)
;
System.out.println(this.getName()+":"+i);
}
}
}