码迷,mamicode.com
首页 > 其他好文 > 详细

ExecutorService 用例

时间:2017-11-21 18:47:48      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:oid   exe   clipboard   href   new   com   keyword   data   executors   

 

 

[java] view plain copy
 
  1. import java.util.concurrent.ExecutorService;   
  2. import java.util.concurrent.Executors;   
  3.   
  4. public class TestCachedThreadPool{   
  5.     public static void main(String[] args){   
  6.         ExecutorService executorService = Executors.newCachedThreadPool();   
  7. //      ExecutorService executorService = Executors.newFixedThreadPool(5);  
  8. //      ExecutorService executorService = Executors.newSingleThreadExecutor();  
  9.         for (int i = 0; i < 5; i++){   
  10.             executorService.execute(new TestRunnable());   
  11.             System.out.println("************* a" + i + " *************");   
  12.         }   
  13.         executorService.shutdown();   
  14.     }   
  15. }   
  16.   
  17. class TestRunnable implements Runnable{   
  18.     public void run(){   
  19.         System.out.println(Thread.currentThread().getName() + "线程被调用了。");   
  20.     }   

 

ExecutorService 用例

标签:oid   exe   clipboard   href   new   com   keyword   data   executors   

原文地址:http://www.cnblogs.com/ydxblog/p/7874566.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!