关于线程池的shutdown()方法

在需要把线程池活动线程全部停止时需要使用shutdown()方法,但当线程池的队列很长时,即使使用了shutdown()方法,清除了当前活动线程,但队列中的线程依然可以加入线程池,这样一达不到停止全部线程的要求。

清除全部线程的代码如下

protected ExecutorService executorService;
public void stop() {
        ((ThreadPoolExecutor) executorService).getQueue().clear();
        executorService.shutdown();
    }

 

 

posted @ 2013-01-13 16:17  sonicit  阅读(1092)  评论(0编辑  收藏  举报