线程优先级问题

//Java线程优先级范围1-10  默认为5  在cpu同一时间片内 优先级大的抢占cpu优势大   

public class Test {
    public static void main(String[] args) {
        Thread t1 = new MyThread1();
        Thread t2 = new Thread(new MyRunnable());
        t1.setPriority(10);
        t2.setPriority(1);

        t2.start();
        t1.start();
    }
}

class MyThread1 extends Thread {
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println("线程1第" + i + "次执行!");
        }
    }
}

class MyRunnable implements Runnable {
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println("线程2第" + i + "次执行!");
        }
    }
}

 

posted @ 2015-06-12 00:40  NPH  阅读(539)  评论(0编辑  收藏  举报