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

  • Post author:
  • Post category:java


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);
        }
    }
}



版权声明:本文为u011424470原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。