我是在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不支持时间片轮换??

解决方案 »

  1.   

    我晕 上面的main()方法里面就一个线程  所以不会并发 根本就是个单线程的程序
    我给你一段代码你运行一下: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);
    }
    }
    }
      

  2.   

    不是有个main线程吗?还有一个我自己定义的线程啊
      

  3.   

    不是vista的问题,main是主线程,肯定的先运行,线程的优先级高只是得到cpu的使用机会大,不会时间更长
      

  4.   

    我是说根本不会出现线程的时间片轮换,如果不是在mian线程中定义了index,就一直执行,mian线程,不知道有没明白我的意思
      

  5.   

    兄弟:是操作系统的原因,在win 2000和win xp上面演示多线程的时候会有差距的,特别是在2000上面的优先级体现的不是很明显,你可以去别人的xp系统上面测试下注意给分
      

  6.   

    4楼的放屁,谁说的main一定先执行
      

  7.   

    我在win7下,除了mian线程外又定义了两个线程,也是发现不支持时间片轮换