下面列出了怎么用com.google.common.util.concurrent.ForwardingExecutorService的API类实例代码及写法,或者点击链接到github查看源代码。
public static ExecutorService blocksOnFirstCallFromCallableOfType(final ExecutorService delegate, final Class<? extends Callable> type) {
return new ForwardingExecutorService() {
private boolean firstCall = true;
@Override
protected ExecutorService delegate() {
return delegate;
}
@Override
public <T> Future<T> submit(Callable<T> task) {
if (task.getClass().equals(type) && firstCall) {
firstCall = false;
try {
return Futures.immediateFuture(task.call());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return super.submit(task);
}
};
}