Reputation: 942
public class MyCallable implements Callable<Boolean> {
@Override
public Boolean call() {
while(true){
try{
[... stuff]
}catch(Exception e){
System.out.println("Error!");
}
}
}
}
public static void main(String[] args) throws Exception {
int parallelCallables = 6;
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
.setNameFormat("Grabber-thread-%d").build();
facebookInfoGrabberExecutor = Executors.newFixedThreadPool(parallelCallables, namedThreadFactory);
List<Future<Boolean>> futures = facebookInfoGrabberExecutor.invokeAll(tasks);
System.out.println("unreachable");
}
Despite the fact that it seems impossibile my program can print "unreachable". When it reach that line all process are in WAIT. I use hazelcast, that could be the culprit, in a way that I still do not know.
Upvotes: 1
Views: 75
Reputation: 65813
You need to shut down your Executor
to make it complete all tasks.
int parallelCallables = 6;
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
.setNameFormat("Grabber-thread-%d").build();
ExecutorService facebookInfoGrabberExecutor = Executors.newFixedThreadPool(parallelCallables, namedThreadFactory);
List<Future<Boolean>> futures = facebookInfoGrabberExecutor.invokeAll(tasks);
// Add this!!!
facebookInfoGrabberExecutor.shutdown();
while (!facebookInfoGrabberExecutor.awaitTermination(1, TimeUnit.MINUTES)) {
System.out.println("Waiting");
}
System.out.println("All done.");
Upvotes: 1