Они ВСЕ должны завершиться должным образом без исключений.
Если один из них выйдет из строя, мне придется немедленно остановить их все, а не ждать несколько минут, пока они завершат бесполезную работу. Как я могу это сделать? Это часть моего текущего кода:
Код: Выделить всё
ExecutorService executorService = Executors.newFixedThreadPool(iNumThread);
List callableTasks = new ArrayList();
for (int i = 0; i < iNumThread; i++) {
callableTasks.add(new ExecuteJob(...));
}
List resultList = null;
try {
resultList = executorService.invokeAll(callableTasks);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
executorService.shutdown();
// This cycle doesn't work for me because it waits for all threads to finish even if one or more have given an exception.
while (!executorService.isTerminated()) {
//DO SOMETHING LIKE UPDATE UI, ETC
}
//check result
for (int i = 0; i < resultList.size(); i++) {
Future future = resultList.get(i);
try {
String result = future.get();
if (!result.equals("OK")){
//ohi ohi
}
} catch (InterruptedException | ExecutionException e) {
//ohi ohi
e.printStackTrace();
}
}
Надеюсь, я ясно выразился. Спасибо большое.
Макс
Подробнее здесь: https://stackoverflow.com/questions/798 ... hread-fail
Мобильная версия