我使用ThreadPoolExecutor
管理的线程数,我可以通过ThreadFactory->newThread()
赶上创建线程池一个新的线程的情况下,但现在我知道如何捕捉杀死线程的事件,按照以下配置停留2分钟。检测空闲时的ThreadPoolExecutor线程被杀害
我hae搜索了一个侦听器的方法,但找不到。
public abstract class ThreadPoolEventProcessor<E> implements ThreadFactory{
private BlockingQueue<Runnable> taskQueue;
private ThreadPoolExecutor executor;
protected ThreadPoolEventProcessor(int coreThreadSize, int maxQueueSize) {
taskQueue = new LinkedBlockingQueue<Runnable>(maxQueueSize);
executor = new ThreadPoolExecutor(coreThreadSize, coreThreadSize * 5, 2L, TimeUnit.MINUTES, taskQueue,this);
executor.prestartAllCoreThreads();
}
public Thread newThread(Runnable r) {
return new Thread(r, getWorkerName());
}
我不明白你的问题。 – 2014-09-01 20:55:09
更新了我的问题,我真正想要的是检测线程被执行者杀死的事件的情况。 – 2014-09-01 21:03:30
执行程序不会终止线程。线程在其run()方法返回时停止。 – 2014-09-01 21:04:48