java多线程示例展示优先级源代码:

 1 package control;
 2 
 3 /**
 4  * 功能:龟兔赛跑
 5  *            线程控制优先级别
 6  * 
 7  *         总结:怎么设置优先级?
 8  *             setPriority 
 9  *             通过设置优先级,数字越大的优先级别越高(1-10)  获取cpu概率大
10  *             默认优先级是5
11  *             final static 
12  *             MIN_PRIORITY  1
13  *             MAX_PRIORITY  10
14  *             通过写到run方法的设置优先级 还有启动线程设置优先级  在run方法中设置的生效
15  * @author superdrew
16  *
17  */
18 public class TestThread1 {
19     public static void main(String[] args) {
20         TortoiseThread tt = new TortoiseThread("乌龟线程");
21         //设置线程优先级
22         tt.setPriority(2);
23         tt.start();
24         
25         RabbitRunnable rr = new RabbitRunnable();
26         Thread tr = new Thread(rr);
27         tr.setName("兔子线程");
28         //设置线程优先级
29         tr.setPriority(9);
30         tr.start();
31         
32         
33     }
34 }
Test.java

相关文章:

  • 2021-07-12
  • 2021-06-17
  • 2021-12-01
  • 2022-12-23
猜你喜欢
  • 2021-08-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2021-11-01
  • 2022-12-23
相关资源
相似解决方案