本文整理汇总了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);
}
}