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


Java Uninterruptibles.getUninterruptibly方法代码示例

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


在下文中一共展示了Uninterruptibles.getUninterruptibly方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: refresh

import com.google.common.util.concurrent.Uninterruptibles; //导入方法依赖的package包/类
/**
 * Refreshes the value associated with {@code key}, unless another thread is already doing so.
 * Returns the newly refreshed value associated with {@code key} if it was refreshed inline, or
 * {@code null} if another thread is performing the refresh or if an error occurs during
 * refresh.
 */
@Nullable
V refresh(K key, int hash, CacheLoader<? super K, V> loader, boolean checkTime) {
  final LoadingValueReference<K, V> loadingValueReference =
      insertLoadingValueReference(key, hash, checkTime);
  if (loadingValueReference == null) {
    return null;
  }

  ListenableFuture<V> result = loadAsync(key, hash, loadingValueReference, loader);
  if (result.isDone()) {
    try {
      return Uninterruptibles.getUninterruptibly(result);
    } catch (Throwable t) {
      // don't let refresh exceptions propagate; error was already logged
    }
  }
  return null;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:25,代码来源:LocalCache.java

示例2: getUncheckedExcept

import com.google.common.util.concurrent.Uninterruptibles; //导入方法依赖的package包/类
/**
 * Get the result of the given {@link Future}, retrying if interrupted using
 * {@link Uninterruptibles#getUninterruptibly}, and wrap any checked exceptions
 * other than the one given using {@link Throwables#propagate(Throwable)}.
 *
 * Use this when you only need to handle a particular checked exception,
 * and want any others can be handled generically.
 */
public static <T, E extends Throwable> T getUncheckedExcept(Future<T> future, Class<E> except) throws E {
    try {
        return Uninterruptibles.getUninterruptibly(future);
    } catch(ExecutionException e) {
        if(except.isInstance(e.getCause())) {
            throw except.cast(e.getCause());
        } else {
            throw Throwables.propagate(e);
        }
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:20,代码来源:FutureUtils.java

示例3: get

import com.google.common.util.concurrent.Uninterruptibles; //导入方法依赖的package包/类
public static <T> T get(Future<T> future) {
    try {
        return Uninterruptibles.getUninterruptibly(future);
    } catch (ExecutionException e) {
        throw propagateCause(e);
    }
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:8,代码来源:CassandraUtil.java


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