ExecutionException and InterruptedException while using Future class's get() method
Posted
by java_geek
on Stack Overflow
See other posts from Stack Overflow
or by java_geek
Published on 2010-04-19T06:38:27Z
Indexed on
2010/04/19
6:43 UTC
Read the original article
Hit count: 304
ExecutorService executor = Executors.newSingleThreadExecutor();
try {
Task t = new Task(response,inputToPass,pTypes,unit.getInstance(),methodName,unit.getUnitKey());
Future<SCCallOutResponse> fut = executor.submit(t);
response = fut.get(unit.getTimeOut(),TimeUnit.MILLISECONDS);
}
catch (TimeoutException e) {
// if the task is still running, a TimeOutException will occur while fut.get()
cat.error("Unit " + unit.getUnitKey() + " Timed Out");
response.setVote(SCCallOutConsts.TIMEOUT);
} catch (InterruptedException e) {
cat.error(e);
} catch (ExecutionException e) {
cat.error(e);
}
finally {
executor.shutdown();
}
}
How should i handle the InterruptedException and ExecutionException in the code? And in what cases are these exceptions thrown?
© Stack Overflow or respective owner