The Sun Java (1.6) ScheduledThreadPoolExecutor
which is an extension of ThreadPoolExecutor
internally uses an implementation of DelayQueue
which is an unbounded queue. What I need is a ScheduledThreadpoolExecutor
with a bounded queue i.e. it has a limit on the tasks accumulating in the queue so that when tasks in queue exceed the limit, it starts rejecting the further submitted tasks and prevents JVM going out of memory.
Surprisingly, google or stackoverflow did not point me to any results which are discussing this problem. Is there any such thing already available I am missing out? If not, how can I implement a ScheduledThreadpoolExecutor to provide me my expected functionality in a best way?