user1156041
user1156041

Reputation: 2195

ThreadPoolExecutor throws RejectedExecutionException after shutting down

I have two buttons for start download and stop download. I used the ThreadPoolExecutor for multiple downloads. I shut down the ThreadPoolExecutor when the stop button is clicked. And I start execution again on ThreadPoolExecutor when the start button is clicked. I got RejectedExecutionException. I would like to know that how to re-execute the ThreadPoolExecutor that has already shutdown.

EDIT: error stack.

11-18 10:41:52.929: E/AndroidRuntime(27351): FATAL EXCEPTION: main
11-18 10:41:52.929: E/AndroidRuntime(27351): java.util.concurrent.RejectedExecutionException: Task com.task.SyncTask@42614978 rejected from java.util.concurrent.ThreadPoolExecutor@414ce138[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 181]
11-18 10:41:52.929: E/AndroidRuntime(27351):    at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1979)
11-18 10:41:52.929: E/AndroidRuntime(27351):    at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:786)
11-18 10:41:52.929: E/AndroidRuntime(27351):    at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1307)
11-18 10:41:52.929: E/AndroidRuntime(27351):    at com.MainActivity$2.handleMessage(MainActivity.java:394)
11-18 10:41:52.929: E/AndroidRuntime(27351):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-18 10:41:52.929: E/AndroidRuntime(27351):    at android.os.Looper.loop(Looper.java:213)
11-18 10:41:52.929: E/AndroidRuntime(27351):    at android.app.ActivityThread.main(ActivityThread.java:5092)
11-18 10:41:52.929: E/AndroidRuntime(27351):    at java.lang.reflect.Method.invokeNative(Native Method)
11-18 10:41:52.929: E/AndroidRuntime(27351):    at java.lang.reflect.Method.invoke(Method.java:511)
11-18 10:41:52.929: E/AndroidRuntime(27351):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
11-18 10:41:52.929: E/AndroidRuntime(27351):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:564)
11-18 10:41:52.929: E/AndroidRuntime(27351):    at dalvik.system.NativeStart.main(Native Method)

Thanks.

Upvotes: 0

Views: 1798

Answers (1)

Buddy
Buddy

Reputation: 11028

According to the docs, after calling shutdown "no new tasks will be accepted".

You shouldn't need to explicitly shutdown the executor (it'll take care of that itself once all the threads in it are done).

Is there a message in the RejectedExecutionException you're getting?

Upvotes: 1

Related Questions