本文整理汇总了Java中org.apache.commons.lang3.concurrent.LazyInitializer类的典型用法代码示例。如果您正苦于以下问题:Java LazyInitializer类的具体用法?Java LazyInitializer怎么用?Java LazyInitializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LazyInitializer类属于org.apache.commons.lang3.concurrent包,在下文中一共展示了LazyInitializer类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handlePotentialStuckRepairs
import org.apache.commons.lang3.concurrent.LazyInitializer; //导入依赖的package包/类
private void handlePotentialStuckRepairs(LazyInitializer<Set<String>> busyHosts, String hostName)
throws ConcurrentException {
if (!busyHosts.get().contains(hostName) && context.storage instanceof IDistributedStorage) {
try (JmxProxy hostProxy
= context.jmxConnectionFactory.connect(hostName, context.config.getJmxConnectionTimeoutInSeconds())) {
// We double check that repair is still running there before actually canceling repairs
if (hostProxy.isRepairRunning()) {
LOG.warn(
"A host ({}) reported that it is involved in a repair, but there is no record "
+ "of any ongoing repair involving the host. Sending command to abort all repairs "
+ "on the host.",
hostName);
hostProxy.cancelAllRepairs();
hostProxy.close();
}
} catch (ReaperException | RuntimeException | InterruptedException | JMException e) {
LOG.debug("failed to cancel repairs on host {}", hostName, e);
}
}
}
示例2: lazy
import org.apache.commons.lang3.concurrent.LazyInitializer; //导入依赖的package包/类
/**
* Use a supplier to perform lazy instantiation of a value. Wraps the given
* supplier in a new Supplier that has the lazy loading logic.
*/
public static <T> Supplier<T> lazy(Supplier<T> source) {
return new Supplier<T>() {
final LazyInitializer<T> init = new LazyInitializer<T>() {
@Override
protected T initialize() throws ConcurrentException {
return source.get();
}
};
@Override
public T get() {
try {
return init.get();
} catch (ConcurrentException e) {
throw new IllegalStateException(e);
}
}
};
}
示例3: Sum
import org.apache.commons.lang3.concurrent.LazyInitializer; //导入依赖的package包/类
public Sum(int a, int b) {
this.a = a;
this.b = b;
mSum = new LazyInitializer<Integer>() {
@Override
protected Integer initialize() throws ConcurrentException {
return Sum.this.a + Sum.this.b;
}
};
}