com.google.common.base.Stopwatch.isRunning()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(118)

本文整理了Java中com.google.common.base.Stopwatch.isRunning()方法的一些代码示例,展示了Stopwatch.isRunning()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stopwatch.isRunning()方法的具体详情如下:
包路径:com.google.common.base.Stopwatch
类名称:Stopwatch
方法名:isRunning

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

  1. ImmutableMap<Service, Long> startupTimes() {
  2. List<Entry<Service, Long>> loadTimes;
  3. monitor.enter();
  4. try {
  5. loadTimes = Lists.newArrayListWithCapacity(startupTimers.size());
  6. // N.B. There will only be an entry in the map if the service has started
  7. for (Entry<Service, Stopwatch> entry : startupTimers.entrySet()) {
  8. Service service = entry.getKey();
  9. Stopwatch stopWatch = entry.getValue();
  10. if (!stopWatch.isRunning() && !(service instanceof NoOpService)) {
  11. loadTimes.add(Maps.immutableEntry(service, stopWatch.elapsed(MILLISECONDS)));
  12. }
  13. }
  14. } finally {
  15. monitor.leave();
  16. }
  17. Collections.sort(
  18. loadTimes,
  19. Ordering.natural()
  20. .onResultOf(
  21. new Function<Entry<Service, Long>, Long>() {
  22. @Override
  23. public Long apply(Entry<Service, Long> input) {
  24. return input.getValue();
  25. }
  26. }));
  27. return ImmutableMap.copyOf(loadTimes);
  28. }

代码示例来源:origin: google/guava

  1. public void testCreateStarted() {
  2. Stopwatch startedStopwatch = Stopwatch.createStarted();
  3. assertTrue(startedStopwatch.isRunning());
  4. }

代码示例来源:origin: google/j2objc

  1. ImmutableMap<Service, Long> startupTimes() {
  2. List<Entry<Service, Long>> loadTimes;
  3. monitor.enter();
  4. try {
  5. loadTimes = Lists.newArrayListWithCapacity(startupTimers.size());
  6. // N.B. There will only be an entry in the map if the service has started
  7. for (Entry<Service, Stopwatch> entry : startupTimers.entrySet()) {
  8. Service service = entry.getKey();
  9. Stopwatch stopWatch = entry.getValue();
  10. if (!stopWatch.isRunning() && !(service instanceof NoOpService)) {
  11. loadTimes.add(Maps.immutableEntry(service, stopWatch.elapsed(MILLISECONDS)));
  12. }
  13. }
  14. } finally {
  15. monitor.leave();
  16. }
  17. Collections.sort(
  18. loadTimes,
  19. Ordering.natural()
  20. .onResultOf(
  21. new Function<Entry<Service, Long>, Long>() {
  22. @Override
  23. public Long apply(Entry<Service, Long> input) {
  24. return input.getValue();
  25. }
  26. }));
  27. return ImmutableMap.copyOf(loadTimes);
  28. }

代码示例来源:origin: google/guava

  1. public void testStop_alreadyStopped() {
  2. stopwatch.start();
  3. stopwatch.stop();
  4. try {
  5. stopwatch.stop();
  6. fail();
  7. } catch (IllegalStateException expected) {
  8. }
  9. assertFalse(stopwatch.isRunning());
  10. }

代码示例来源:origin: google/guava

  1. public void testStop() {
  2. stopwatch.start();
  3. assertSame(stopwatch, stopwatch.stop());
  4. assertFalse(stopwatch.isRunning());
  5. }

代码示例来源:origin: google/guava

  1. public void testStart_whileRunning() {
  2. stopwatch.start();
  3. try {
  4. stopwatch.start();
  5. fail();
  6. } catch (IllegalStateException expected) {
  7. }
  8. assertTrue(stopwatch.isRunning());
  9. }

代码示例来源:origin: google/guava

  1. public void testStop_new() {
  2. try {
  3. stopwatch.stop();
  4. fail();
  5. } catch (IllegalStateException expected) {
  6. }
  7. assertFalse(stopwatch.isRunning());
  8. }

代码示例来源:origin: wildfly/wildfly

  1. ImmutableMap<Service, Long> startupTimes() {
  2. List<Entry<Service, Long>> loadTimes;
  3. monitor.enter();
  4. try {
  5. loadTimes = Lists.newArrayListWithCapacity(startupTimers.size());
  6. // N.B. There will only be an entry in the map if the service has started
  7. for (Entry<Service, Stopwatch> entry : startupTimers.entrySet()) {
  8. Service service = entry.getKey();
  9. Stopwatch stopWatch = entry.getValue();
  10. if (!stopWatch.isRunning() && !(service instanceof NoOpService)) {
  11. loadTimes.add(Maps.immutableEntry(service, stopWatch.elapsed(MILLISECONDS)));
  12. }
  13. }
  14. } finally {
  15. monitor.leave();
  16. }
  17. Collections.sort(
  18. loadTimes,
  19. Ordering.natural()
  20. .onResultOf(
  21. new Function<Entry<Service, Long>, Long>() {
  22. @Override
  23. public Long apply(Entry<Service, Long> input) {
  24. return input.getValue();
  25. }
  26. }));
  27. return ImmutableMap.copyOf(loadTimes);
  28. }

代码示例来源:origin: google/guava

  1. public void testInitialState() {
  2. assertFalse(stopwatch.isRunning());
  3. assertEquals(0, stopwatch.elapsed(NANOSECONDS));
  4. }

代码示例来源:origin: google/guava

  1. public void testStart() {
  2. assertSame(stopwatch, stopwatch.start());
  3. assertTrue(stopwatch.isRunning());
  4. }

代码示例来源:origin: google/guava

  1. startupTimers.put(service, stopwatch);
  2. if (to.compareTo(RUNNING) >= 0 && stopwatch.isRunning()) {

代码示例来源:origin: google/guava

  1. public void testCreateUnstarted() {
  2. Stopwatch unstartedStopwatch = Stopwatch.createUnstarted();
  3. assertFalse(unstartedStopwatch.isRunning());
  4. assertEquals(0, unstartedStopwatch.elapsed(NANOSECONDS));
  5. }

代码示例来源:origin: google/guava

  1. public void testReset_new() {
  2. ticker.advance(1);
  3. stopwatch.reset();
  4. assertFalse(stopwatch.isRunning());
  5. ticker.advance(2);
  6. assertEquals(0, stopwatch.elapsed(NANOSECONDS));
  7. stopwatch.start();
  8. ticker.advance(3);
  9. assertEquals(3, stopwatch.elapsed(NANOSECONDS));
  10. }

代码示例来源:origin: google/guava

  1. public void testReset_whileRunning() {
  2. ticker.advance(1);
  3. stopwatch.start();
  4. assertEquals(0, stopwatch.elapsed(NANOSECONDS));
  5. ticker.advance(2);
  6. assertEquals(2, stopwatch.elapsed(NANOSECONDS));
  7. stopwatch.reset();
  8. assertFalse(stopwatch.isRunning());
  9. ticker.advance(3);
  10. assertEquals(0, stopwatch.elapsed(NANOSECONDS));
  11. }

代码示例来源:origin: google/j2objc

  1. startupTimers.put(service, stopwatch);
  2. if (to.compareTo(RUNNING) >= 0 && stopwatch.isRunning()) {

代码示例来源:origin: apache/hive

  1. case KILL_REQUESTED:
  2. LOG.info("Killed task {}", requestId);
  3. if (killtimerWatch.isRunning()) {
  4. killtimerWatch.stop();
  5. long elapsed = killtimerWatch.elapsed(TimeUnit.MILLISECONDS);

代码示例来源:origin: wildfly/wildfly

  1. startupTimers.put(service, stopwatch);
  2. if (to.compareTo(RUNNING) >= 0 && stopwatch.isRunning()) {

代码示例来源:origin: twitter/distributedlog

  1. @Override
  2. public void run() {
  3. synchronized(scheduleLock) {
  4. if (scheduleDelayStopwatch.isRunning()) {
  5. scheduleLatency.registerSuccessfulEvent(scheduleDelayStopwatch.stop().elapsed(TimeUnit.MICROSECONDS));

代码示例来源:origin: twitter/distributedlog

  1. if (lastLedgerCloseDetected.isRunning()) {
  2. if (lastLedgerCloseDetected.elapsed(TimeUnit.MILLISECONDS)
  3. > conf.getReaderIdleWarnThresholdMillis()) {

代码示例来源:origin: lenskit/lenskit

  1. /**
  2. * Record that an item has been completed.
  3. */
  4. public void advance() {
  5. Preconditions.checkState(timer.isRunning(), "progress logger not running");
  6. int n = ndone.incrementAndGet();
  7. if (logger.isTraceEnabled()) {
  8. logger.trace("finished {} of {} items", n, total);
  9. }
  10. if (n % period == 0) {
  11. logProgress();
  12. } else {
  13. // log every 30 seconds
  14. long micros = timer.elapsed(TimeUnit.MICROSECONDS);
  15. if (micros - prevMicros > timePeriod) {
  16. logProgress(micros);
  17. }
  18. }
  19. }

相关文章