Android(java)學習筆記63:線程的調度

來源:互聯網
上載者:User

標籤:

 1 package cn.itcast_04; 2  3 /* 4  * 我們的線程沒有設定優先權,肯定有預設優先順序。 5  * 那麼,預設優先順序是多少呢? 6  * 如何擷取線程對象的優先順序? 7  *         public final int getPriority():返回線程對象的優先順序 8  * 如何設定線程對象的優先順序呢? 9  *         public final void setPriority(int newPriority):更改線程的優先順序。 10  * 11  * 注意:12  *         線程預設優先順序是5。13  *         線程優先順序的範圍是:1-10。14  *         線程優先順序高僅僅表示線程擷取的 CPU時間片的幾率高,但是要在次數比較多,或者多次啟動並執行時候才能看到比較好的效果。15  *         16  * IllegalArgumentException:非法參數異常。17  * 拋出的異常表明向方法傳遞了一個不合法或不正確的參數。 18  * 19  */20 public class ThreadPriorityDemo {21     public static void main(String[] args) {22         ThreadPriority tp1 = new ThreadPriority();23         ThreadPriority tp2 = new ThreadPriority();24         ThreadPriority tp3 = new ThreadPriority();25 26         tp1.setName("東方不敗");27         tp2.setName("嶽不群");28         tp3.setName("林平之");29 30         // 擷取預設優先順序31         // System.out.println(tp1.getPriority());32         // System.out.println(tp2.getPriority());33         // System.out.println(tp3.getPriority());34 35         // 設定線程優先順序36         // tp1.setPriority(100000);37         38         //設定正確的線程優先順序,tp3這裡沒有設定,表示預設設定tp3 = 539         tp1.setPriority(10);40         tp2.setPriority(1);41 42         tp1.start();43         tp2.start();44         tp3.start();45     }46 }

 

Android(java)學習筆記63:線程的調度

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.