本文整理了Java中com.google.common.base.Stopwatch.isRunning()
方法的一些代码示例,展示了Stopwatch.isRunning()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stopwatch.isRunning()
方法的具体详情如下:
包路径:com.google.common.base.Stopwatch
类名称:Stopwatch
方法名:isRunning
[英]Returns true if #start() has been called on this stopwatch, and #stop() has not been called since the last call to start().
[中]如果已在此秒表上调用#start(),且自上次调用start()以来未调用#stop(),则返回true。
代码示例来源:origin: google/guava
ImmutableMap<Service, Long> startupTimes() {
List<Entry<Service, Long>> loadTimes;
monitor.enter();
try {
loadTimes = Lists.newArrayListWithCapacity(startupTimers.size());
// N.B. There will only be an entry in the map if the service has started
for (Entry<Service, Stopwatch> entry : startupTimers.entrySet()) {
Service service = entry.getKey();
Stopwatch stopWatch = entry.getValue();
if (!stopWatch.isRunning() && !(service instanceof NoOpService)) {
loadTimes.add(Maps.immutableEntry(service, stopWatch.elapsed(MILLISECONDS)));
}
}
} finally {
monitor.leave();
}
Collections.sort(
loadTimes,
Ordering.natural()
.onResultOf(
new Function<Entry<Service, Long>, Long>() {
@Override
public Long apply(Entry<Service, Long> input) {
return input.getValue();
}
}));
return ImmutableMap.copyOf(loadTimes);
}
代码示例来源:origin: google/guava
public void testCreateStarted() {
Stopwatch startedStopwatch = Stopwatch.createStarted();
assertTrue(startedStopwatch.isRunning());
}
代码示例来源:origin: google/j2objc
ImmutableMap<Service, Long> startupTimes() {
List<Entry<Service, Long>> loadTimes;
monitor.enter();
try {
loadTimes = Lists.newArrayListWithCapacity(startupTimers.size());
// N.B. There will only be an entry in the map if the service has started
for (Entry<Service, Stopwatch> entry : startupTimers.entrySet()) {
Service service = entry.getKey();
Stopwatch stopWatch = entry.getValue();
if (!stopWatch.isRunning() && !(service instanceof NoOpService)) {
loadTimes.add(Maps.immutableEntry(service, stopWatch.elapsed(MILLISECONDS)));
}
}
} finally {
monitor.leave();
}
Collections.sort(
loadTimes,
Ordering.natural()
.onResultOf(
new Function<Entry<Service, Long>, Long>() {
@Override
public Long apply(Entry<Service, Long> input) {
return input.getValue();
}
}));
return ImmutableMap.copyOf(loadTimes);
}
代码示例来源:origin: google/guava
public void testStop_alreadyStopped() {
stopwatch.start();
stopwatch.stop();
try {
stopwatch.stop();
fail();
} catch (IllegalStateException expected) {
}
assertFalse(stopwatch.isRunning());
}
代码示例来源:origin: google/guava
public void testStop() {
stopwatch.start();
assertSame(stopwatch, stopwatch.stop());
assertFalse(stopwatch.isRunning());
}
代码示例来源:origin: google/guava
public void testStart_whileRunning() {
stopwatch.start();
try {
stopwatch.start();
fail();
} catch (IllegalStateException expected) {
}
assertTrue(stopwatch.isRunning());
}
代码示例来源:origin: google/guava
public void testStop_new() {
try {
stopwatch.stop();
fail();
} catch (IllegalStateException expected) {
}
assertFalse(stopwatch.isRunning());
}
代码示例来源:origin: wildfly/wildfly
ImmutableMap<Service, Long> startupTimes() {
List<Entry<Service, Long>> loadTimes;
monitor.enter();
try {
loadTimes = Lists.newArrayListWithCapacity(startupTimers.size());
// N.B. There will only be an entry in the map if the service has started
for (Entry<Service, Stopwatch> entry : startupTimers.entrySet()) {
Service service = entry.getKey();
Stopwatch stopWatch = entry.getValue();
if (!stopWatch.isRunning() && !(service instanceof NoOpService)) {
loadTimes.add(Maps.immutableEntry(service, stopWatch.elapsed(MILLISECONDS)));
}
}
} finally {
monitor.leave();
}
Collections.sort(
loadTimes,
Ordering.natural()
.onResultOf(
new Function<Entry<Service, Long>, Long>() {
@Override
public Long apply(Entry<Service, Long> input) {
return input.getValue();
}
}));
return ImmutableMap.copyOf(loadTimes);
}
代码示例来源:origin: google/guava
public void testInitialState() {
assertFalse(stopwatch.isRunning());
assertEquals(0, stopwatch.elapsed(NANOSECONDS));
}
代码示例来源:origin: google/guava
public void testStart() {
assertSame(stopwatch, stopwatch.start());
assertTrue(stopwatch.isRunning());
}
代码示例来源:origin: google/guava
startupTimers.put(service, stopwatch);
if (to.compareTo(RUNNING) >= 0 && stopwatch.isRunning()) {
代码示例来源:origin: google/guava
public void testCreateUnstarted() {
Stopwatch unstartedStopwatch = Stopwatch.createUnstarted();
assertFalse(unstartedStopwatch.isRunning());
assertEquals(0, unstartedStopwatch.elapsed(NANOSECONDS));
}
代码示例来源:origin: google/guava
public void testReset_new() {
ticker.advance(1);
stopwatch.reset();
assertFalse(stopwatch.isRunning());
ticker.advance(2);
assertEquals(0, stopwatch.elapsed(NANOSECONDS));
stopwatch.start();
ticker.advance(3);
assertEquals(3, stopwatch.elapsed(NANOSECONDS));
}
代码示例来源:origin: google/guava
public void testReset_whileRunning() {
ticker.advance(1);
stopwatch.start();
assertEquals(0, stopwatch.elapsed(NANOSECONDS));
ticker.advance(2);
assertEquals(2, stopwatch.elapsed(NANOSECONDS));
stopwatch.reset();
assertFalse(stopwatch.isRunning());
ticker.advance(3);
assertEquals(0, stopwatch.elapsed(NANOSECONDS));
}
代码示例来源:origin: google/j2objc
startupTimers.put(service, stopwatch);
if (to.compareTo(RUNNING) >= 0 && stopwatch.isRunning()) {
代码示例来源:origin: apache/hive
case KILL_REQUESTED:
LOG.info("Killed task {}", requestId);
if (killtimerWatch.isRunning()) {
killtimerWatch.stop();
long elapsed = killtimerWatch.elapsed(TimeUnit.MILLISECONDS);
代码示例来源:origin: wildfly/wildfly
startupTimers.put(service, stopwatch);
if (to.compareTo(RUNNING) >= 0 && stopwatch.isRunning()) {
代码示例来源:origin: twitter/distributedlog
@Override
public void run() {
synchronized(scheduleLock) {
if (scheduleDelayStopwatch.isRunning()) {
scheduleLatency.registerSuccessfulEvent(scheduleDelayStopwatch.stop().elapsed(TimeUnit.MICROSECONDS));
代码示例来源:origin: twitter/distributedlog
if (lastLedgerCloseDetected.isRunning()) {
if (lastLedgerCloseDetected.elapsed(TimeUnit.MILLISECONDS)
> conf.getReaderIdleWarnThresholdMillis()) {
代码示例来源:origin: lenskit/lenskit
/**
* Record that an item has been completed.
*/
public void advance() {
Preconditions.checkState(timer.isRunning(), "progress logger not running");
int n = ndone.incrementAndGet();
if (logger.isTraceEnabled()) {
logger.trace("finished {} of {} items", n, total);
}
if (n % period == 0) {
logProgress();
} else {
// log every 30 seconds
long micros = timer.elapsed(TimeUnit.MICROSECONDS);
if (micros - prevMicros > timePeriod) {
logProgress(micros);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!