sonicit

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

清除全部线程的代码如下

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

 

 

分类:

技术点:

相关文章:

  • 2022-02-06
  • 2021-09-04
  • 2022-01-07
  • 2022-02-15
  • 2022-12-23
  • 2022-01-07
  • 2022-01-02
  • 2022-01-07
猜你喜欢
  • 2022-01-07
  • 2022-01-07
  • 2022-01-07
  • 2022-01-07
  • 2022-01-07
  • 2022-01-07
相关资源
相似解决方案