本文整理了Java中java.time.Duration.plusMillis()
方法的一些代码示例,展示了Duration.plusMillis()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Duration.plusMillis()
方法的具体详情如下:
包路径:java.time.Duration
类名称:Duration
方法名:plusMillis
[英]Returns a copy of this duration with the specified duration in milliseconds added.
This instance is immutable and unaffected by this method call.
[中]返回此持续时间的副本,并添加指定的持续时间(以毫秒为单位)。
此实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: ehcache/ehcache3
public static long getExpirationMillis(long now, Duration duration) {
try {
return duration.plusMillis(now).toMillis();
} catch (ArithmeticException e) {
return Long.MAX_VALUE;
}
}
代码示例来源:origin: Alluxio/alluxio
@Override
protected Duration computeNextWaitTime() {
Duration next = mNextSleep;
mNextSleep = mNextSleep.multipliedBy(2);
if (mNextSleep.compareTo(mMaxSleep) > 0) {
mNextSleep = mMaxSleep;
}
// Add jitter.
long jitter = Math.round(ThreadLocalRandom.current().nextDouble(0.1) * next.toMillis());
return next.plusMillis(jitter);
}
代码示例来源:origin: reactor/reactor-core
jitter = random.nextLong(lowBound, highBound);
Duration effectiveBackoff = nextBackoff.plusMillis(jitter);
return Mono.delay(effectiveBackoff);
});
代码示例来源:origin: debezium/debezium
long expectedMillis = Duration.ofHours(17).plusMinutes(51).plusSeconds(4).plusMillis(780).toMillis();
assertThat(c2).isEqualTo((int)expectedMillis);
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this duration with the specified duration in milliseconds subtracted.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param millisToSubtract the milliseconds to subtract, positive or negative
* @return a {@code Duration} based on this duration with the specified milliseconds subtracted, not null
* @throws ArithmeticException if numeric overflow occurs
*/
public Duration minusMillis(long millisToSubtract) {
return (millisToSubtract == Long.MIN_VALUE ? plusMillis(Long.MAX_VALUE).plusMillis(1) : plusMillis(-millisToSubtract));
}
代码示例来源:origin: org.ehcache/ehcache
public static long getExpirationMillis(long now, Duration duration) {
try {
return duration.plusMillis(now).toMillis();
} catch (ArithmeticException e) {
return Long.MAX_VALUE;
}
}
代码示例来源:origin: zeebe-io/zeebe
/**
* Will run all tasks scheduled since the last time this was executed + the given duration.
*
* @param elapsed upper bound of tasks delay
*/
public void runScheduledTasks(Duration elapsed) {
final Duration upperBound = elapsed.plusMillis(lastRanAtMs);
scheduledTasks.stream()
.filter(t -> t.getDelay().compareTo(upperBound) <= 0)
.sorted(Comparator.comparing(MockScheduledTask::getDelay))
.forEach(MockScheduledTask::run);
lastRanAtMs = upperBound.toMillis();
}
}
代码示例来源:origin: io.zeebe/zeebe-test
/**
* Will run all tasks scheduled since the last time this was executed + the given duration.
*
* @param elapsed upper bound of tasks delay
*/
public void runScheduledTasks(Duration elapsed) {
final Duration upperBound = elapsed.plusMillis(lastRanAtMs);
scheduledTasks.stream()
.filter(t -> t.getDelay().compareTo(upperBound) <= 0)
.sorted(Comparator.comparing(MockScheduledTask::getDelay))
.forEach(MockScheduledTask::run);
lastRanAtMs = upperBound.toMillis();
}
}
代码示例来源:origin: org.alluxio/alluxio-core-common
@Override
protected Duration computeNextWaitTime() {
Duration next = mNextSleep;
mNextSleep = mNextSleep.multipliedBy(2);
if (mNextSleep.compareTo(mMaxSleep) > 0) {
mNextSleep = mMaxSleep;
}
// Add jitter.
long jitter = Math.round(ThreadLocalRandom.current().nextDouble(0.1) * next.toMillis());
return next.plusMillis(jitter);
}
代码示例来源:origin: com.atlassian.bamboo.plugins.dotnet/atlassian-bamboo-plugin-dotnet
/**
* Convert hh:mm:ss.mmmmmmm format to Duration
* @param input
* @return
*/
private Optional<Duration> convertDuration(String input)
{
final Matcher matcher = DURATION_FORMAT.matcher(input);
if (matcher.matches())
{
final long hh = Long.parseLong(matcher.group(1));
final long mm = Long.parseLong(matcher.group(2));
final long ss = Long.parseLong(matcher.group(3));
final long ms = Long.parseLong(matcher.group(4));
return Optional.of(Duration.ofHours(hh)
.plusMinutes(mm)
.plusSeconds(ss)
.plusMillis(ms));
}
else
{
log.warn(String.format("Cannot parse duration string [%s]", input));
return Optional.empty();
}
}
代码示例来源:origin: org.nuxeo.common/nuxeo-common
millis = Long.parseLong(matcher.group(5));
return Duration.ofDays(days).plusHours(hours).plusMinutes(minutes).plusSeconds(seconds).plusMillis(
millis);
代码示例来源:origin: io.projectreactor.addons/reactor-extra
@Override
public Duration apply(BackoffDelay backoff) {
//check the invariant
if (backoff.delay.compareTo(backoff.min) < 0) {
throw new IllegalArgumentException("jitter can only be applied on a delay that is >= to min backoff");
}
if (backoff.delay.compareTo(backoff.max) > 0) {
throw new IllegalArgumentException("jitter can only be applied on a delay that is <= to max backoff");
}
//short-circuit delay == 0 case
if (backoff.delay.isZero()) {
return backoff.delay;
}
ThreadLocalRandom random = ThreadLocalRandom.current();
long jitterOffset = jitterOffsetCapped(backoff);
long lowBound = lowJitterBound(backoff, jitterOffset);
long highBound = highJitterBound(backoff, jitterOffset);
long jitter;
if (highBound == lowBound) {
if (highBound == 0) jitter = 0;
else jitter = random.nextLong(highBound);
}
else {
jitter = random.nextLong(lowBound, highBound);
}
return backoff.delay.plusMillis(jitter);
}
代码示例来源:origin: io.projectreactor/reactor-core
jitter = random.nextLong(lowBound, highBound);
Duration effectiveBackoff = nextBackoff.plusMillis(jitter);
return Mono.delay(effectiveBackoff);
});
代码示例来源:origin: com.opentable.components/otj-metrics-core
counter.inc();
Thread.sleep(reportingPeriod.plusMillis(400).toMillis());
Assert.assertTrue(server.getBytesRead() > 0);
Assert.assertTrue(server.contains("post adding counter", "foo.bar.baz"));
代码示例来源:origin: org.hibernate.validator/hibernate-validator
@Override
public void initialize(DurationMin constraintAnnotation) {
this.minDuration = Duration.ofNanos( constraintAnnotation.nanos() )
.plusMillis( constraintAnnotation.millis() )
.plusSeconds( constraintAnnotation.seconds() )
.plusMinutes( constraintAnnotation.minutes() )
.plusHours( constraintAnnotation.hours() )
.plusDays( constraintAnnotation.days() );
this.inclusive = constraintAnnotation.inclusive();
}
代码示例来源:origin: org.hibernate.validator/hibernate-validator
@Override
public void initialize(DurationMax constraintAnnotation) {
this.maxDuration = Duration.ofNanos( constraintAnnotation.nanos() )
.plusMillis( constraintAnnotation.millis() )
.plusSeconds( constraintAnnotation.seconds() )
.plusMinutes( constraintAnnotation.minutes() )
.plusHours( constraintAnnotation.hours() )
.plusDays( constraintAnnotation.days() );
this.inclusive = constraintAnnotation.inclusive();
}
代码示例来源:origin: com.github.seratch/java-time-backport
case NANOS: return plusNanos(amountToAdd);
case MICROS: return plusSeconds((amountToAdd / (1000000L * 1000)) * 1000).plusNanos((amountToAdd % (1000000L * 1000)) * 1000);
case MILLIS: return plusMillis(amountToAdd);
case SECONDS: return plusSeconds(amountToAdd);
代码示例来源:origin: io.zeebe/zeebe-broker-core
.addTime(MessageObserver.MESSAGE_TIME_TO_LIVE_CHECK_INTERVAL.plusMillis(timeToLive));
代码示例来源:origin: zeebe-io/zeebe
.addTime(MessageObserver.MESSAGE_TIME_TO_LIVE_CHECK_INTERVAL.plusMillis(timeToLive));
代码示例来源:origin: io.debezium/debezium-connector-mysql
long expectedMillis = Duration.ofHours(17).plusMinutes(51).plusSeconds(4).plusMillis(780).toMillis();
assertThat(c2).isEqualTo((int)expectedMillis);
内容来源于网络,如有侵权,请联系作者删除!