當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。