零EVA

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

优先级代表着抢资源的频率

所有线程默认优先级是5

yield()临时释放线程的执行权

 1 class Demo implements Runnable
 2 {
 3     public void run()
 4     {
 5         for(int x = 0; x < 70; x++)
 6         {
 7             System.out.println(Thread.currentThread().toString()+"..."+x);
 8             Thread.yield();
 9         }
10     }
11 }
12 
13 class JoinDemo
14 {
15     public static void main(String[] args) throws Exception
16     {
17         Demo d = new Demo();
18         Thread t1 = new Thread(d);
19         Thread t2 = new Thread(d);
20         t1.start();
21         //t1.join();
22         //t1.setPriority(Thread.MAX_PRIORITY);
23         t2.start();
24         for(int x = 0; x < 70; x++)
25         {
26             //System.out.println("main..."+x);
27         }
28         System.out.println("over");
29     }
30 }
View Code

 

posted on 2017-06-23 21:58  零EVA  阅读(187)  评论(0编辑  收藏  举报