Removing all queued tasks of an ThreadPoolExecutor

前端 未结 10 1845
日久生厌
日久生厌 2020-12-03 03:10

i have this rather simple question about the ThreadPoolExecutor. I have the following situation: I have to consume objects from a queue, create the appropiate worker tasks f

10条回答
  •  感情败类
    2020-12-03 03:21

    I used to work on an app with long running threads. We do this at shutdown,

    BlockingQueue queue = threadPool.getQueue();
    List list = new ArrayList();
    int tasks = queue.drainTo(list);
    

    The list is saved to a file. On startup, the list is added back to the pool so we don't lose any jobs.

提交回复
热议问题