使用newSingleThreadExecutor()創建靜態線程池


 1     public static void main(String[] args) {
 2         //始終只有一個線程在執行
 3         //使用newSingleThreadExecutor()創建靜態線程池
 4         ExecutorService SinglePool = Executors.newSingleThreadExecutor();
 5         for (int i = 0; i < 10; i++) {
 6             SinglePool.execute(new MyThead02(i));
 7         }
 8     }
 9 }
10 class MyThead02 implements Runnable{
11     int num;
12 
13     public MyThead02(int num) {
14         super();
15         this.num = num;
16     }
17     @Override
18     public void run() {
19         System.out.println(Thread.currentThread().getName()+":"+num);    
20     }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM