Moving a List <Future> object throws an IndexOutOfBounds exception
I have an ExecutorService that is used to call the Callable obejcts collection and returns List of Future objects matching the Callable elements in the collection.
However, somewhere, moving the list, it throws the following exception:
java.util.concurrent.ExecutionException: java.lang.IndexOutOfBoundsException: Index: 7, Size: 1
at java.util.concurrent.FutureTask.report(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at com.soc.transformcsv.ParallelTransformationPool.doExecute(ParallelTransformationPool.java:91)
The code I was executing
List<Future<StringBuilder>> futures = executor.invokeAll(builders);
executor.shutdown();
HashMap<String, List<StringBuilder>> allServiceTypeRows = new LinkedHashMap<>();
for (Future<StringBuilder> future : futures) {
// I have tried putting future.isDone() which always prints true before the exception
StringBuilder recordBuilder = future.get();
// do more
}
This gives me an error in the line future.get().
Please help resolve the roadblock or let me know what else I provide.
+4
2 answers
The result isDone()may be true, even if Callable has an exception. From the isDonedocumentation :
true, . , - true.
, , , , . , , , "Caused by:" - Callable.
Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.RuntimeException: This is a failure!
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at Ideone.main(Main.java:16)
Caused by: java.lang.RuntimeException: This is a failure!
at Ideone$SampleCallable.call(Main.java:21)
at Ideone$SampleCallable.call(Main.java:19)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at Ideone.main(Main.java:14)
+4