I create the following executor in a singleton:
final private ExecutorService executor = Executors.newSingleThreadExecutor(new ThreadFactory() {
You might have submitted tasks after calling executor.shutdown()
. Normally to stop executor they do
executor.shutdown();
executor.awaitTermination(10, TimeUnit.MINUTES);
Maybe you should use a thread pool instead of using a single executor.
executor = new java.util.concurrent.ThreadPoolExecutor(30, 30, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {
final AtomicInteger threadNumber = new AtomicInteger( 1 );
@Override
public Thread newThread(Runnable r) {
return new Thread(r, "Thread No : " + threadNumber.getAndIncrement());
}
});
There are two reasons why execute
would throw a RejectedExecutionException
Since you are using a LinkedBlockingQueue
the only way I can see this occurring is because you shutdown the pool.
Threads are not available to execute the given task. No linked block queue to que task.