-1

Here is my case:

I am using the Thread Pool to run multiple tasks.

I would like to suspend the threads that receive exceptions with some kind of like Eclipse debuger's effect. And when I decide that these suspended threads can be run again, I can resume them to run these tasks.

Can anyone give me any suggestion?

Unheilig
  • 16,196
  • 193
  • 68
  • 98

1 Answers1

0

Two Logical steps to be taken here...

1.) To check if any task in your thread pool throws an exception.

2.) If any of them do then shutdown the executor service which would stop all currently executing threads....(check docs)

For first point...use Callable and Futures....instead of runnable.. this way you can determine the status of a Task execution..

How to properly catch RuntimeExceptions from Executors?

check this link for further details on coding....

look at future.get documentation to understand what different exceptions are thrown....

Community
  • 1
  • 1
acearch
  • 343
  • 1
  • 8
  • thanks for your reply first . after pause all threads i still want resume them so i think just shutdown the threadpool is not enough. – Andrew Deng May 29 '15 at 02:07
  • http://stackoverflow.com/questions/9748710/how-to-pause-resume-all-threads-in-an-executorservice-in-java...... this link might help... – acearch Jun 01 '15 at 10:02