当前位置: 首页>>代码示例>>Java>>正文


Java Duration.ofMillis方法代码示例

本文整理汇总了Java中java.time.Duration.ofMillis方法的典型用法代码示例。如果您正苦于以下问题:Java Duration.ofMillis方法的具体用法?Java Duration.ofMillis怎么用?Java Duration.ofMillis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.Duration的用法示例。


在下文中一共展示了Duration.ofMillis方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: formatAsElapsed

import java.time.Duration; //导入方法依赖的package包/类
public static String formatAsElapsed() {
    Duration elapsed = Duration.ofMillis(ManagementFactory.getRuntimeMXBean().getUptime());
    long days = elapsed.toDays();
    elapsed = elapsed.minusDays(days);
    long hours = elapsed.toHours();
    elapsed = elapsed.minusHours(hours);
    long minutes = elapsed.toMinutes();
    elapsed = elapsed.minusMinutes(minutes);
    long seconds = elapsed.getSeconds();
    elapsed = elapsed.minusSeconds(seconds);
    long millis = elapsed.toMillis();

    return String.format(TIME_FORMAT,
            days,
            hours,
            minutes,
            seconds,
            millis);
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:20,代码来源:TimeUtils.java

示例2: testCustomDelayForReturnValueRetry

import java.time.Duration; //导入方法依赖的package包/类
@Test public void testCustomDelayForReturnValueRetry() throws Exception {
  TestDelay<String> delay = new TestDelay<String>() {
    @Override public Duration duration() {
      return Duration.ofMillis(1);
    }
  };
  Retryer.ForReturnValue<String> forReturnValue =
      retryer.ifReturns(s -> s.startsWith("bad"), asList(delay).stream());
  when(action.run()).thenReturn("bad").thenReturn("fixed");
  CompletionStage<String> stage = forReturnValue.retry(action::run, executor);
  elapse(Duration.ofMillis(1));
  assertCompleted(stage).isEqualTo("fixed");
  verify(action, times(2)).run();
  assertThat(delay.before).isEqualTo("bad");
  assertThat(delay.after).isEqualTo("bad");
}
 
开发者ID:google,项目名称:mug,代码行数:17,代码来源:RetryerTest.java

示例3: AngerRenderer

import java.time.Duration; //导入方法依赖的package包/类
public AngerRenderer(Loop maxLoopCount) {
    super(maxLoopCount);
    emotionImage = ImageResources.emotionAnger();

    ArrayList<KeyFrameAnimation.KeyFrame> animX = new ArrayList<>();
    ArrayList<KeyFrameAnimation.KeyFrame> animY = new ArrayList<>();
    Instant now = Instant.now();
    double r = 1f / pos.length;
    for (int i = 1; i < pos.length; i++) {
        LinearAnimation x = new LinearAnimation(now, Duration.ZERO);
        x.setFromValue(ImageUtil.defaultScale(pos[i - 1][0]));
        x.setToValue(ImageUtil.defaultScale(pos[i][0]));
        animX.add(new KeyFrameAnimation.KeyFrame(r * (i - 1), r * i, x));

        LinearAnimation y = new LinearAnimation(now, Duration.ZERO);
        y.setFromValue(ImageUtil.defaultScale(pos[i][1]));
        y.setToValue(ImageUtil.defaultScale(pos[i - 1][1]));
        animY.add(new KeyFrameAnimation.KeyFrame(r * (i - 1), r * i, y));
    }

    moveX = new KeyFrameAnimation(now, Duration.ofMillis(2000), animX);
    moveY = new KeyFrameAnimation(now, Duration.ofMillis(2000), animY);

    fade.setFromValue(1);
    fade.setToValue(0);
}
 
开发者ID:orekyuu,项目名称:Riho,代码行数:27,代码来源:AngerRenderer.java

示例4: eventually

import java.time.Duration; //导入方法依赖的package包/类
private void eventually(Runnable work) throws Exception {
    Duration patience = Duration.ofSeconds(1);
    Duration interval = Duration.ofMillis(15);
    int remaining = (int) (patience.toMillis() / interval.toMillis());

    while (true) {
        try {
            work.run();
            return;
        } catch (Exception | AssertionError e) {
            if (remaining-- == 0) {
                throw e;
            }
            Thread.sleep(interval.toMillis());
        }
    }
}
 
开发者ID:tim-group,项目名称:tg-eventstore,代码行数:18,代码来源:EndToEndTest.java

示例5: should_wait_notasktimeout_when_no_task_found

import java.time.Duration; //导入方法依赖的package包/类
@Test
public void should_wait_notasktimeout_when_no_task_found() throws Exception {
    Duration betweenTaskTimeout = Duration.ofHours(1L);
    Duration noTaskTimeout = Duration.ofMillis(5L);

    QueueConsumer queueConsumer = mock(QueueConsumer.class);
    TaskPicker taskPicker = mock(TaskPicker.class);
    when(taskPicker.pickTask(queueConsumer)).thenReturn(null);
    TaskProcessor taskProcessor = mock(TaskProcessor.class);

    when(queueConsumer.getQueueConfig()).thenReturn(new QueueConfig(testLocation1,
            QueueSettings.builder().withBetweenTaskTimeout(betweenTaskTimeout).withNoTaskTimeout(noTaskTimeout).build()));
    QueueProcessingStatus status = new QueueRunnerInSeparateTransactions(taskPicker, taskProcessor).runQueue(queueConsumer);

    assertThat(status, equalTo(QueueProcessingStatus.SKIPPED));

    verify(taskPicker).pickTask(queueConsumer);
    verifyZeroInteractions(taskProcessor);
}
 
开发者ID:yandex-money,项目名称:db-queue,代码行数:20,代码来源:QueueRunnerInSeparateTransactionsTest.java

示例6: getShouldRetry

import java.time.Duration; //导入方法依赖的package包/类
/**
 * Returns the corresponding ShouldRetry delegate.
 *
 * @return The ShouldRetry delegate.
 */
@Override
public ShouldRetry getShouldRetry() {
    return (int currentRetryCount,
            RuntimeException lastException,
            ReferenceObjectHelper<Duration> refRetryInterval) -> {
        if (currentRetryCount < this.retryCount) {
            Double delta = this.deltaBackoff == Duration.ZERO ? 0.0
                    : (Math.pow(2.0, currentRetryCount) - 1) * ThreadLocalRandom.current().nextDouble((this.deltaBackoff.getSeconds() * 0.8),
                            (this.deltaBackoff.getSeconds() * 1.2));
            Long interval = Math.min((this.minBackoff.getSeconds() + delta.intValue()), this.maxBackoff.getSeconds());
            refRetryInterval.argValue = Duration.ofMillis(interval);
            return true;
        }

        refRetryInterval.argValue = Duration.ZERO;
        return false;
    };
}
 
开发者ID:Microsoft,项目名称:elastic-db-tools-for-java,代码行数:24,代码来源:ExponentialBackoff.java

示例7: getTimeRemaining

import java.time.Duration; //导入方法依赖的package包/类
/**
 * Get the remaining time, formatted nicely.
 * @return The remaining time.
 */
public String getTimeRemaining(){
	Date now = new Date();
	long remainingMillis = surveyDeadline.getTime() - now.getTime();
	Duration timeRemaining = Duration.ofMillis(remainingMillis);
	
	return DurationFormatter.formatDuration(timeRemaining);
}
 
开发者ID:erikns,项目名称:webpoll,代码行数:12,代码来源:SurveyAnsweringModel.java

示例8: convertMicrosecondsToTimeString

import java.time.Duration; //导入方法依赖的package包/类
/**
 * Convert microseconds to a human readable time string.
 *
 * @param microseconds The amount of microseconds.
 * @return The human readable string representation.
 */
public static String convertMicrosecondsToTimeString(final long microseconds) {
    Duration durationMilliseconds = Duration.ofMillis(microseconds / MICROSECOND_FACTOR);
    long minutes = durationMilliseconds.toMinutes();
    long seconds = durationMilliseconds.minusMinutes(minutes).getSeconds();
    long milliseconds = durationMilliseconds.minusMinutes(minutes).minusSeconds(seconds).toMillis();
    return String.format("%dm %02ds %03dms", minutes, seconds, milliseconds);
}
 
开发者ID:trivago,项目名称:cluecumber-report-plugin,代码行数:14,代码来源:RenderingUtils.java

示例9: testSubmissionTimeoutCancelsInFlightTasks

import java.time.Duration; //导入方法依赖的package包/类
@Test public void testSubmissionTimeoutCancelsInFlightTasks() throws InterruptedException {
  assumeFalse(threading == Threading.DIRECT);
  assumeTrue(mode == Mode.INTERRUPTIBLY);
  maxInFlight = 2;
  timeout = Duration.ofMillis(1);
  assertThrows(
      TimeoutException.class,
      () -> parallelize(serialTasks(
          () -> blockFor(1), // Will be interrupted
          () -> blockFor(2), // Will be interrupted
          () -> translateToString(3))));  // Times out
  shutdownAndAssertInterruptedKeys().containsExactly(1, 2);
  assertThat(translated).doesNotContainKey(3);
}
 
开发者ID:google,项目名称:mug,代码行数:15,代码来源:ParallelizerTest.java

示例10: convert

import java.time.Duration; //导入方法依赖的package包/类
@Override
public Duration convert(String source) {
    source = source.trim();
    if ("0".equals(source)) {
        return Duration.ZERO;
    }
    Matcher matcher = pattern.matcher(source);
    if (!matcher.matches()) throw new IllegalArgumentException("Illegal period: " + source);
    long value = Long.parseLong(matcher.group(1));
    switch (matcher.group(2).toLowerCase()) {
        case "ns":
        case "nanos":
            return Duration.ofNanos(value);
        case "ms":
        case "msec":
        case "millis":
            return Duration.ofMillis(value);
        case "s":
        case "sec":
            return Duration.ofSeconds(value);
        case "m":
        case "min":
            return Duration.ofMinutes(value);
        case "h":
        case "hour":
        case "hours":
            return Duration.ofHours(value);
        case "d":
        case "day":
        case "days":
            return Duration.ofDays(value);
        
    }
    throw new IllegalArgumentException("Illegal unit: " + source);
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:36,代码来源:DurationConverter.java

示例11: parseDuration

import java.time.Duration; //导入方法依赖的package包/类
public static Duration parseDuration(String text) throws DateTimeParseException {
    if("oo".equals(text)) return INF_POSITIVE;

    // If text looks like a plain number, try to parse it as seconds,
    // but be fairly strict so we don't accidentally parse a time as
    // a number.
    if(text.matches("^\\s*-?[0-9]+(\\.[0-9]+)?\\s*$")) {
        try {
            return Duration.ofMillis((long) (1000 * Double.parseDouble(text)));
        } catch(NumberFormatException ignored) {}
    }

    return Durations.parse(text);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:15,代码来源:TimeUtils.java

示例12: factory_millis_long

import java.time.Duration; //导入方法依赖的package包/类
@Test(dataProvider="MillisDurationNoNanos")
public void factory_millis_long(long millis, long expectedSeconds, int expectedNanoOfSecond) {
    Duration test = Duration.ofMillis(millis);
    assertEquals(test.getSeconds(), expectedSeconds);
    assertEquals(test.getNano(), expectedNanoOfSecond);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:TCKDuration.java

示例13: computeDelayBeforeNextRetry

import java.time.Duration; //导入方法依赖的package包/类
@Override
public Duration computeDelayBeforeNextRetry(RetryPolicyContext context) {
    int ceil = calculateExponentialDelay(context.retriesAttempted(), baseDelay, maxBackoffTime, numRetries);
    return Duration.ofMillis((ceil / 2) + random.nextInt((ceil / 2) + 1));
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:6,代码来源:EqualJitterBackoffStrategy.java

示例14: none

import java.time.Duration; //导入方法依赖的package包/类
static BackoffStrategy none() {
    return new FixedDelayBackoffStrategy(Duration.ofMillis(1));
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:4,代码来源:BackoffStrategy.java

示例15: computeDelayBeforeNextRetry

import java.time.Duration; //导入方法依赖的package包/类
@Override
public Duration computeDelayBeforeNextRetry(RetryPolicyContext context) {
    int ceil = calculateExponentialDelay(context.retriesAttempted(), baseDelay, maxBackoffTime, numRetries);
    return Duration.ofMillis(random.nextInt(ceil));
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:6,代码来源:FullJitterBackoffStrategy.java


注:本文中的java.time.Duration.ofMillis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。