本文整理匯總了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;
}
示例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);
}
}
}
示例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);
}
}