Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the causes of RejctedExecutionException?

Are there any other causes for RejectedExecutionException being thrown besides shutdown() being called previously on the Executor (I'm using a singleThreadExecutor)? I have some crash reports as below. They are very rare and I can't reproduce on my devices. My code is too complex to post, but I'm not seeing how it's logically possible that any tasks are being submitted after shutdown() is called.

Are there any other reasons that RejectedExecutionException could be thrown here?

java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@4194a5f0 rejected from java.util.concurrent.ThreadPoolExecutor@41a36e90[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 9813] at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1979) at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:786) at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1307) at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:81) at java.util.concurrent.Executors$DelegatedExecutorService.submit(Executors.java:562) at com.smp.soundtouchandroid.AACFileAudioSink.write(AACFileAudioSink.java:28) at com.smp.soundtouchandroid.SoundStreamRunnable.processChunk(SoundStreamRunnable.java:469) at com.smp.soundtouchandroid.SoundStreamRunnable.processFile(SoundStreamRunnable.java:406) at com.smp.soundtouchandroid.SoundStreamRunnable.run(SoundStreamRunnable.java:223) at java.lang.Thread.run(Thread.java:856)

like image 200
Steve M Avatar asked Oct 04 '14 02:10

Steve M


People also ask

How do you handle RejectedExecutionException?

If you have constrained your thread pool to only allow a certain number of concurrent threads (generally a good thing), then the application needs to somehow push-back on the calling code, so when you receive a RejectedExecutionException from the ThreadPoolExecutor you need to indicate this to the caller and the caller ...

What is Java Util Concurrent RejectedExecutionException?

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.

What is executors newFixedThreadPool?

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.


1 Answers

See http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

Your ThreadPoolExecutor is shutdown, or

ThreadPoolExecutor has a finite number of threads, or work queue has finite capacity and is full (e.g., LinkedBlockingQueue of finite capacity passed in to ThreadPoolExecutor constructor).

like image 71
rtsai2000 Avatar answered Nov 07 '22 08:11

rtsai2000