package com.bijian.study;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class WorkerPool {
public static void main(String args[]) throws InterruptedException {
//RejectedExecutionHandler implementation
RejectedExecutionHandlerImpl rejectionHandler = new RejectedExecutionHandlerImpl();
//Get the ThreadFactory implementation to use
ThreadFactory threadFactory = Executors.defaultThreadFactory();
//creating the ThreadPoolExecutor
ThreadPoolExecutor executorPool = new ThreadPoolExecutor(2, 4, 10, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(3), threadFactory, rejectionHandler);
//start the monitoring thread
MyMonitorThread monitor = new MyMonitorThread(executorPool, 3);
Thread monitorThread = new Thread(monitor);
monitorThread.start();
//submit work to the thread pool
for(int i=0; i<10; i++){
executorPool.execute(new WorkerThread("cmd"+i));
}
Thread.sleep(30000);
//shut down the pool
executorPool.shutdown();
//shut down the monitor thread
Thread.sleep(5000);
monitor.shutdown();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
线程池实例:使用Executors和ThreadPoolExecutor
共13个文件
class:5个
java:5个
classpath:1个
需积分: 32 2 下载量 143 浏览量
2019-08-12
01:53:14
上传
评论
收藏 8KB RAR 举报
温馨提示
NULL 博文链接:https://bijian1013.iteye.com/blog/2284676
资源推荐
资源详情
资源评论
收起资源包目录
ThreadPoolExecutor.rar (13个子文件)
ThreadPoolExecutor
.project 394B
src
com
bijian
study
WorkerPool.java 1KB
WorkerThread.java 695B
SimpleThreadPool.java 564B
MyMonitorThread.java 1KB
RejectedExecutionHandlerImpl.java 381B
.settings
org.eclipse.jdt.core.prefs 598B
.classpath 302B
bin
com
bijian
study
SimpleThreadPool.class 1KB
MyMonitorThread.class 2KB
RejectedExecutionHandlerImpl.class 1KB
WorkerPool.class 2KB
WorkerThread.class 1KB
共 13 条
- 1
资源评论
weixin_38669628
- 粉丝: 387
- 资源: 6万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功