类com.google.common.util.concurrent.ForwardingExecutorService源码实例Demo

下面列出了怎么用com.google.common.util.concurrent.ForwardingExecutorService的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: ibm-cos-sdk-java   文件: TestExecutors.java
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);
        }
    };
}
 
 类方法
 同包方法