当前位置: 首页>>代码示例>>Java>>正文


Java ForwardingListenableFuture类代码示例

本文整理汇总了Java中com.google.common.util.concurrent.ForwardingListenableFuture的典型用法代码示例。如果您正苦于以下问题:Java ForwardingListenableFuture类的具体用法?Java ForwardingListenableFuture怎么用?Java ForwardingListenableFuture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ForwardingListenableFuture类属于com.google.common.util.concurrent包,在下文中一共展示了ForwardingListenableFuture类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: scopeCallbacks

import com.google.common.util.concurrent.ForwardingListenableFuture; //导入依赖的package包/类
public <T> ListenableFuture<T> scopeCallbacks(final ListenableFuture<T> callback) {
    final ScopedObjects scope = getScope();
    return new ForwardingListenableFuture<T>() {
        @Override
        protected ListenableFuture<T> delegate() {
            return callback;
        }

        @Override
        public void addListener(Runnable listener, Executor exec) {
            super.addListener(listener, scope(exec, scope));
        }
    };
}
 
开发者ID:yahoo,项目名称:yql-plus,代码行数:15,代码来源:ExecutionScoper.java

示例2: wrapListenableFuture

import com.google.common.util.concurrent.ForwardingListenableFuture; //导入依赖的package包/类
private <T> ListenableFuture<T> wrapListenableFuture(final ListenableFuture<T> delegate) {
    /*
     * This creates a forwarding Future that overrides calls to get(...) to check, via the
     * ThreadLocal, if the caller is doing a blocking call on a thread from this executor. If
     * so, we detect this as a deadlock and throw an ExecutionException even though it may not
     * be a deadlock if there are more than 1 thread in the pool. Either way, there's bad
     * practice somewhere, either on the client side for doing a blocking call or in the
     * framework's threading model.
     */
    return new ForwardingListenableFuture.SimpleForwardingListenableFuture<T>(delegate) {
        @Override
        public T get() throws InterruptedException, ExecutionException {
            checkDeadLockDetectorTL();
            return super.get();
        }

        @Override
        public T get(final long timeout, @Nonnull final TimeUnit unit)
                throws InterruptedException, ExecutionException, TimeoutException {
            checkDeadLockDetectorTL();
            return super.get(timeout, unit);
        }

        void checkDeadLockDetectorTL() throws ExecutionException {
            if (deadlockDetector.get().isSet()) {
                throw new ExecutionException("A potential deadlock was detected.",
                        deadlockExceptionFunction.get());
            }
        }
    };
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:32,代码来源:DeadlockDetectingListeningExecutorService.java


注:本文中的com.google.common.util.concurrent.ForwardingListenableFuture类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。