JAVA多线程Thread setPriority 设置线程优先级方法入门详解

package com.yys.thread;


/**
 * Created by yys on 2017/9/20.
 * 测试 Thread setPriority方法
 * 设置线程优先级
 * 输出为
 T1 : 7488
 T1 : 7489
 ---T2 : 5
 T1 : 7490
 T1 : 7491
 */
public class TestPriority {
    public static void main(String[] args){
        Thread t1 = new Thread(new T1());
        Thread t2 = new Thread(new T2());
        t1.setPriority(Thread.NORM_PRIORITY + 3);
        t1.start();
        t2.start();
    }
}

class T1 implements Runnable{
    @Override
    public void run() {
        for(int i=0;i<=10000;i++){
            System.out.println("T1 : " + i);
        }
    }
}

class T2 implements Runnable{
    @Override
    public void run() {
        for(int i=0;i<=1000;i++){
            System.out.println("---T2 : " + i);
        }
    }
}

你可能感兴趣的:(java)