有如下的一个线程池
threadPoolExecutor = new ThreadPoolExecutor(1, 50, 1000L, TimeUnit.SECONDS, new BlockingQueueOfExecutor(500, true));
while(true){
for(Iterator iterator = taskList.iterator(); iterator.hasNext();)
{
SfCollecttask task = (SfCollecttask)iterator.next();
Runnable run = new CollectThread(task, collecttaskDao, collectinfoDao, dslamDAO, statitemparaDAO,collectionNum, threadPoolExecutor);
threadPoolExecutor.execute(run);
}
}
如果线程池里面有800 个线程,,,如果有5个线程执行完了之后 也就是?CollectThread 的run方法完成之后,我要将所有的线程给停止了,那么我该真么做呢
threadPoolExecutor = new ThreadPoolExecutor(1, 50, 1000L, TimeUnit.SECONDS, new BlockingQueueOfExecutor(500, true));
while(true){
for(Iterator iterator = taskList.iterator(); iterator.hasNext();)
{
SfCollecttask task = (SfCollecttask)iterator.next();
Runnable run = new CollectThread(task, collecttaskDao, collectinfoDao, dslamDAO, statitemparaDAO,collectionNum, threadPoolExecutor);
threadPoolExecutor.execute(run);
}
}
如果线程池里面有800 个线程,,,如果有5个线程执行完了之后 也就是?CollectThread 的run方法完成之后,我要将所有的线程给停止了,那么我该真么做呢
设置一个计数器,在run方法结束的时候更新。
添加一个Timer,定时去检测计数器中的值,如果大于5,将标志状态设置为false
切记,在计数器和标志状态的操作时加同步。