[concurrency-interest] Bounded Task Queue for ScheduledThreadPoolExecutor

Volkan Yazıcı volkan.yazici at gmail.com
Tue Apr 23 02:37:31 EDT 2019


Given a ScheduledThreadPoolExecutor (STPE) with a set of slow consumers,
the unbounded task queue constitutes the perfect disguise for
backpressure-related problems. Producers just keep on pushing tasks to the
point that 1) growing queue starts choking memory, 2) almost all pending
time-sensitive tasks become obsolete when they are assigned to a thread to
get executed, and 3) even relatively cheap tasks starve to death for no
good reason. To the best of my knowledge, unfortunately, STPE does accept
neither a bound, nor a custom queue in its ctor, even though the internally
used ThreadPoolExecutor (TPE) perfectly allows that[1]. To work around the
problem, I create my own ScheduledExecutorService where time-sensitive
tasks are delegated to an internal STPE and the rest to a TPE. That being
said, I would rather prefer STPE to just accept a custom implementation or
a bound for the task queue it employs.

I plan to create a ticket for such a feature in OpenJDK. Before doing that,
I would appreciate your feedback on my reasoning in case I am missing
something obvious.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20190423/440eb4c5/attachment.html>

More information about the Concurrency-interest mailing list