cpu调用线程是随机分配,通过设置priority,提高线程被cpu代用的比例

 

线程-priority(优先级,分配比例)

 

public class priority8  implements  Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName());
    }

    public static void main(String[] args) {

        Thread thread1 = new Thread(new priority8(),"陈1");
        Thread thread2 = new Thread(new priority8(),"陈2");
        Thread thread3 = new Thread(new priority8(),"陈3");
        thread1.setPriority(Thread.MIN_PRIORITY);
        thread2.setPriority(Thread.MAX_PRIORITY);
        thread3.setPriority(Thread.MAX_PRIORITY);
        thread1.start();
        thread2.start();
        thread3.start();
    }
}

相关文章:

  • 2022-12-23
  • 2021-07-12
  • 2021-10-28
  • 2022-01-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
  • 2021-09-01
  • 2021-12-30
  • 2021-07-06
  • 2021-06-10
相关资源
相似解决方案