Removing all queued tasks of an ThreadPoolExecutor

前端 未结 10 1833
日久生厌
日久生厌 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:38

    This is an old question, but in case this helps somebody else: you could set a volatile boolean when you call shutdown(), and have each submitted task terminate if that boolean is set before really starting. This will allow tasks which have genuinely started to complete, but will prevent queued tasks from starting their actual activity.

提交回复
热议问题