Georgian Citizen
Georgian Citizen

Reputation: 4017

Rejected Execution Exception

I get this error in the log file while thread is running, i don't know where this error occurs since the threads didn't stop and process data with no issues and only my problem that this error appears multiple times in the log file

java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@419a9977 rejected from java.util.concurrent.ScheduledThreadPoolExecutor@2522cdb9[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 2123929]

I did some research, i found that in some places i shutdown the task, but that did not happen at all.

Upvotes: 2

Views: 18976

Answers (2)

Eduml7
Eduml7

Reputation: 19

Old question, but I had the issue and the comment of @lambad saves my day. I had this piece of code:

ttlExecutorService.schedule(new Runnable() {
    public void run() {
...
...
...
    }
}, 1, TimeUnit.MINUTES);

ttlExecutorService.shutdown();

I removed the shutdown call and exception was no longer thrown

Upvotes: 0

lambad
lambad

Reputation: 1066

Without looking at the code we can't really inform you more about the problem. If you look at the exception then it clearly states that the threads have been terminated and their active count is zero. It seems even after shutting down the executor you are trying to process more code using executors. Are you trying to add more task after the call executor.shutdown()

As per docs, New tasks submitted in method execute(Runnable) will be rejected when the Executor has been shut down, and also when the Executor uses finite bounds for both maximum threads and work queue capacity, and is saturated. In either case, the execute method invokes the RejectedExecutionHandler.rejectedExecution(Runnable, ThreadPoolExecutor) method of its RejectedExecutionHandler.

Look at the doc here: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ThreadPoolExecutor.html

Upvotes: 3

Related Questions