JAVA中的多線程(八):線程的優先順序和yield方法

來源:互聯網
上載者:User

標籤:current   ++   open   sys   nbsp   rgs   ide   alt   class   

優先順序代表著搶資源的頻率

所有線程預設優先順序是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 JoinDemo14 {15     public static void main(String[] args) throws Exception16     {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

 

JAVA中的多線程(八):線程的優先順序和yield方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.