UPDATE: I Fixed it with this code(Works only if you know the total tasks count, My case)
int totalThreads = 0;
int finishedThreads = 0;
private void checkExecutorFinished() {
if(finishedThreads == totalThreads) {
// Exceutor threads got finished
System.out.println(shufflingResult);
}
}
private void startMappingPhase() throws Exception {
totalThreads = fileLines.size();
for (String line : fileLines) {
Future future = new ExecutingController().mapping(line);
while (!future.isDone()) {
//
}
shuffle((Collection<Pair<String, Integer>>) future.get());
finishedThreads++;
checkExecutorFinished();
}
}
UPDATE: My question is clear i need to do that by executor submit; not other methods
I'm using executor service to do my tasks, I want to be informed when it's threads get finished, I googled it found out there is a way but by calling executor execute since i'm using executor submit to add my tasks, I didn't find a way to do that so, Is there a way?