Number of tasks (threads) submitted is also not huge in this test scenario.
The exception RejectedExecutionException: Task java.util.concurrent.FutureTask will be thrown for the following reasons. The thread pool is shut down before the thread is processed. The thread pool queue is complete and no further threads can be created.
The error message RejectedExecutionException indicates events are being raised faster than they can be handled by listeners. This typically means there are one or more plugins with @EventListener methods that are processing events directly on the event threads.
static ExecutorService. newCachedThreadPool() Creates a thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available. static ExecutorService. newCachedThreadPool(ThreadFactory threadFactory)
The newFixedThreadPool() method of Executors class creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue. At any point, at most n Threads will be active processing tasks.
You'll need to provide code samples of how you instantiate and call submit
on the pool (IP should be a non-issue here as we don't need details of the internals of your Callable
classes or anything like that).
Based on the information that you've given, you're almost certainly shutting down the executor service somewhere before submitting the callable to it. Check if you make any calls to shutdown
or shutdownNow
, and if so ensure that you're not adding tasks after this point.
Beyond that, you may want to register your own implementation of java.util.concurrent.RejectedExecutionHandler
in order to aid in debugging; its rejectedExecution message will be called whenever the executor is unable to accept a task, so you could put some rudimentary state-inspection logic there to help you find the cause.
I dont see anywhere in the invocation of the Executors.newCachedThreadPool()
methods where a RejectedExecutionException
is thrown. There are only three cases where it appears to be thrown in Java 6:
execute()
on a ThreadPoolExecutor
and the maximum pool size has been reached.execute()
on a ThreadPoolExecutor
at the same time that shutdownNow
, and has essentially lost the race with the shutdownNow
call.ScheduledThreadPoolExecutor
after the executor has been shutdown.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With