ThreadPoolExecutor的使用
来源:互联网 发布:做淘宝新手怎么找货源 编辑:程序博客网 时间:2024/06/08 06:13
//下面任务的执行顺序:
//0,1马上执行(2个预先在的thread被使用)
//2,3放入任务栈(sPoolWorkQueue.size为2)
//4:马上执行(还可以创建一个thread用来执行任务,3-2=1)
//5:被拒绝,因为既不能马上被执行,又不能放入Queue
public class TestThread2 { private static final BlockingQueue<Runnable> sPoolWorkQueue = new LinkedBlockingQueue<Runnable>(2); public static void main(String[] args) { //2:表示线程池中可供使用的线程数目 //3:表示线程池中最大的线程数目 //sPoolWorkQueue的size:可Queue的任务数目 Executor executor = new ThreadPoolExecutor(2, 3, 1, TimeUnit.SECONDS, sPoolWorkQueue); //Executor executor1 = Executors.newSingleThreadExecutor(); for(int i = 0; i < 10; i++){ System.out.println("input begin i: " + i); final int index = i; executor.execute(new Runnable() { @Override public void run() { String name = Thread.currentThread().getName(); System.out.println("run begin: " + index + ", name = " + name); try { Thread.currentThread().sleep(30000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("run end: " + index + ", name = " + name); } }); System.out.println("input end i: " + i); } }}
0 0
- ThreadPoolExecutor的使用
- ThreadPoolExecutor 的使用详解
- ThreadPoolExecutor的使用
- ThreadPoolExecutor的使用
- ThreadPoolExecutor的使用和介绍
- ThreadPoolExecutor的使用和介绍
- ThreadPoolExecutor的分析与使用
- Java 线程 ThreadPoolExecutor 的使用
- ThreadPoolExecutor线程池的使用
- 线程池ThreadPoolExecutor的使用
- ThreadPoolExecutor线程池的使用
- ThreadPoolExecutor使用
- ThreadPoolExecutor使用
- ThreadPoolExecutor使用
- ThreadPoolExecutor使用
- ThreadPoolExecutor线程池的简单使用
- 线程池类 ThreadPoolExecutor的使用
- ThreadPoolExecutor线程池的使用与理解
- Minimum Absolute Difference in BST
- OpenCv-python之基础图像知识
- Spring Session + Redis实现分布式Session共享
- TensorFlow基础知识点(六)/矩阵基本操作
- CSS3实现优酷轮播图
- ThreadPoolExecutor的使用
- 屏幕相关的辅助类
- Maven常用命令整理
- 104-记录锁(概念)
- 简要介绍Logistic 回归
- 蓝桥杯 拦截导弹(dp 最长下降子序列)
- DWR使用指导
- ScrollView常用属性汇总
- Java的重载与覆盖