JAVA高级复习-线程的优先级

/**
 * @description:线程的优先级
 * @date: 2020/7/25 15:56
 * @author: winson
 */
public class ThreadPriority {

    public static void main(String[] args) {

        PriorityThread t1 = new PriorityThread();

        t1.setName("自定义线程T1");
        t1.setPriority(Thread.MAX_PRIORITY);
        Thread.currentThread().setName("主线程");
        Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
        for (int i = 0; i < 5000; i++) {
            System.out.println(Thread.currentThread().getName() + ":" + i + ",线程优先级:" + Thread.currentThread().getPriority());
        }
        t1.start();
    }

}

class PriorityThread extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 5000; i++) {
            System.out.println(currentThread().getName() + ":" + i + ",线程优先级:" + currentThread().getPriority());
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/elnimo/p/13377058.html