ScheduledThreadPoolExecutor$DelayedWorkQueue are filling with cancelled FutureTasks
Environment
- Java
Issue
- We see a large amount of cancelled tasks or runnables sitting in a ScheduledThreadPoolExecutor$DelayedWorkQueue
Resolution
- On Java 7, you can use
setRemoveOnCancelPolicy. Enabling this will let cancelled tasks be removed immediately. - Otherwise, call purge periodically on the scheduled executor to force cancelled tasks to be cleaned up.
Root Cause
- Cancelled tasks are only removed from the executor's queue after their scheduled delay passes
Components
Category
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.