本文整理汇总了Java中com.google.common.util.concurrent.Service.isRunning方法的典型用法代码示例。如果您正苦于以下问题:Java Service.isRunning方法的具体用法?Java Service.isRunning怎么用?Java Service.isRunning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.util.concurrent.Service
的用法示例。
在下文中一共展示了Service.isRunning方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: awaitRunning
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
/** Returns true if the Guava service entered the RUNNING state within the specified time period. */
private boolean awaitRunning(Service service, long timeoutAt) {
if (service.isRunning()) {
return true;
}
long waitMillis = timeoutAt - System.currentTimeMillis();
if (waitMillis <= 0) {
return false;
}
try {
service.start().get(waitMillis, TimeUnit.MILLISECONDS);
} catch (Exception e) {
// Fall through
}
return service.isRunning();
}
示例2: stopAll
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
private void stopAll() throws Exception {
Throwable failureCause = null;
// Stop services in reverse order.
Iterator<Service> itor = services.descendingIterator();
while (itor.hasNext()) {
Service service = itor.next();
try {
if (service.isRunning() || service.state() == State.STARTING) {
service.stopAndWait();
}
} catch (UncheckedExecutionException e) {
// Just catch as we want all services stopped
if (failureCause == null) {
failureCause = e.getCause();
} else {
// Log for sub-sequence service shutdown error, as only the first failure cause will be thrown.
LOG.warn("Failed to stop service {}", service, e);
}
}
}
if (failureCause != null) {
Throwables.propagateIfPossible(failureCause, Exception.class);
throw new RuntimeException(failureCause);
}
}