你的位置:首页 > 软件开发 > Java > 第十二章 ThreadPoolExecutor使用与工作机理

第十二章 ThreadPoolExecutor使用与工作机理

发布时间:2016-01-20 22:00:31
1、最基础的线程池ThreadPoolExecutor使用方式: 1 /** 2 * ThreadPoolExecutor测试类 3 * 注意: 4 * 1、ThreadPoolExecutor是一个线程池 5 * 2、多个任务都可以由该线程池中选出几条线程来执行 6 * ...

1、最基础的线程池ThreadPoolExecutor

使用方式:

第十二章 ThreadPoolExecutor使用与工作机理第十二章 ThreadPoolExecutor使用与工作机理
 1 /** 2  * ThreadPoolExecutor测试类 3  * 注意: 4  * 1、ThreadPoolExecutor是一个线程池 5  * 2、多个任务都可以由该线程池中选出几条线程来执行 6 */ 7 public class ThreadPoolExecutorTest { 8   private static ThreadPoolExecutor executor =  9       new ThreadPoolExecutor(5, 10, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));10   11   public void executeTask(){12     Task1 task1 = new Task1();//构建任务113     Task2 task2 = new Task2();//构建任务214     executor.execute(task1);//执行任务115     executor.execute(task2);//执行任务216   }17   18   /*19    * 基本任务220   */21   class Task1 implements Runnable{22     public void run() {23       //具体任务的业务24       for(int i=0;i<1000;i++){25         System.out.println("hello xxx!!!");26       }27     }28   }29   30   /*31    * 基本任务232   */33   class Task2 implements Runnable{34     public void run() {35       //具体任务的业务36       for(int i=0;i<5;i++){37         System.out.println("hello world2!!!");38       }39     }40   }41   42   public static void main(String[] args) {43     ThreadPoolExecutorTest test = new ThreadPoolExecutorTest();44     test.executeTask();45   }46 }

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:第十二章 ThreadPoolExecutor使用与工作机理

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录