나는 약간의 javadoc를 읽고 있던 나는 누군가가 코드가있는 경우 첫 번째 전달할 수있는 방법을 나에게 설명 할 수 this example from ThreadPoolExecutor.afterExecute(...)
javadocs:Runnable instanceof Future <?>?
class ExtendedExecutor extends ThreadPoolExecutor {
// ...
protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
if (t == null && r instanceof Future<?>) {
try {
Object result = ((Future<?>) r).get();
} catch (CancellationException ce) {
t = ce;
} catch (ExecutionException ee) {
t = ee.getCause();
} catch (InterruptedException ie) {
Thread.currentThread().interrupt(); // ignore/reset
}
}
if (t != null)
System.out.println(t);
}
}
을 가로 질러왔다. 내 말은 r
이 instanceof가 될 수 있다는 뜻입니까 Future<?>
?
당신은 그것이 왜 가능하지 않다고 생각하는지 설명 할 수 있습니까? – ruakh
음, 아마도'r'은 [RunnableFuture] (http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/RunnableFuture.html)입니다. – azurefrog
'Foo는 Runnable, Future를 구현합니다 {...}' –