0

I have a class A that implements Runnable interface, this class perform my batch job. Their is a controller class which is responsible for creating ExecutorService and submitting objects of Class A to ExecutorService instance in a for loop.

I want to terminated the execution of all task, if any task execution encounters exception as their is high probability that the exception will be caused in all task and I want the cause to be thrown to caller code.

How can I achieve this ?

Ninad
  • 474
  • 8
  • 26
  • 1
    possible duplicate of http://stackoverflow.com/questions/2248131/handling-exceptions-from-java-executorservice-tasks – P.J.Meisch Aug 04 '15 at 17:57

1 Answers1

0

As far as I can tell there is no magic on offer in the Jdk to mangage the cancellataion of the tasks (after a problem in another sibling thread). Looks like you need to keep track of the Future instances and manage the cancellation yourself.

Or find a library that has done the work for you. It might be worth investigating if Spring Batch supports this kind of case.

welterw8
  • 106
  • 1
  • 7