JAVA线程池
来源:互联网 发布:微信摇一摇赛跑软件 编辑:程序博客网 时间:2024/06/06 13:20
public class ThreadPool {
private BlockingQueue taskQueue = null;
private List<PoolThread> threads = new ArrayList<PoolThread>();
private boolean isStopped = false;
public ThreadPool(int noOfThreads, int maxNoOfTasks) {
taskQueue = new BlockingQueue(maxNoOfTasks);
for (int i=0; i<noOfThreads; i++) {
threads.add(new PoolThread(taskQueue));
}
for (PoolThread thread : threads) {
thread.start();
}
}
public void synchronized execute(Runnable task) {
if(this.isStopped) throw
new IllegalStateException("ThreadPool is stopped");
this.taskQueue.enqueue(task);
}
public synchronized boolean stop() {
this.isStopped = true;
for (PoolThread thread : threads) {
thread.stop();
}
}
}
<span style="color: rgb(102, 102, 102); font-family: Arial, Helvetica, sans-serif; line-height: 35px; widows: auto; background-color: rgb(255, 255, 255);">(校注:原文有编译错误,我修改了下)</span>
- Java线程:线程池
- java--线程--线程池
- Java线程(六):线程池
- Java线程(五):线程池
- Java线程(五):线程池
- Java线程_07_线程池
- Java线程(五):线程池
- Java线程(六):线程池
- Java线程(五):线程池
- Java线程(六):线程池
- Java线程(六):线程池
- Java线程(六):线程池
- Java线程(六):线程池
- Java线程(六):线程池
- Java线程(六):线程池
- Java线程(六):线程池
- Java线程(五):线程池
- Java线程(六):线程池
- 黑马程序员--内存管理知识总结
- JVM
- flash编程打地鼠游戏(1.思路)
- 正则表达式基础用法
- 安装BCM43142 802.11b/g/n Linux 驱动
- JAVA线程池
- unity 中用vs 打开cs脚本找不到关联类
- 明源售楼系统技术解析 签约管理(一)
- 设计模式学习笔记--装饰模式
- iOS判断字符串是否符合格式要求
- MySQL truncate
- 《影响数学发展的20个大问题》读书笔记
- JAVA基础——正则表达式
- java单例模式详解