本文整理了Java中java.time.Duration.toMillis()
方法的一些代码示例,展示了Duration.toMillis()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Duration.toMillis()
方法的具体详情如下:
包路径:java.time.Duration
类名称:Duration
方法名:toMillis
[英]Converts this duration to the total length in milliseconds.
If this duration is too large to fit in a long milliseconds, then an exception is thrown.
If this duration has greater than millisecond precision, then the conversion will drop any excess precision information as though the amount in nanoseconds was subject to integer division by one million.
[中]将此持续时间转换为总长度(毫秒)。
如果此持续时间太长,无法容纳很长的毫秒,则会引发异常。
如果此持续时间的精度大于毫秒,则转换将删除任何多余的精度信息,就像以纳秒为单位的量被整数除以一百万一样。
代码示例来源:origin: spring-projects/spring-framework
/**
* Schedule the given {@link Runnable}, starting as soon as possible and invoking it with
* the given delay between the completion of one execution and the start of the next.
* <p>Execution will end once the scheduler shuts down or the returned
* {@link ScheduledFuture} gets cancelled.
* @param task the Runnable to execute whenever the trigger fires
* @param delay the delay between the completion of one execution and the start of the next
* @return a {@link ScheduledFuture} representing pending completion of the task
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
* @since 5.0
* @see #scheduleWithFixedDelay(Runnable, long)
*/
default ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Duration delay) {
return scheduleWithFixedDelay(task, delay.toMillis());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Schedule the given {@link Runnable}, starting as soon as possible and
* invoking it with the given period.
* <p>Execution will end once the scheduler shuts down or the returned
* {@link ScheduledFuture} gets cancelled.
* @param task the Runnable to execute whenever the trigger fires
* @param period the interval between successive executions of the task
* @return a {@link ScheduledFuture} representing pending completion of the task
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
* @since 5.0
* @see #scheduleAtFixedRate(Runnable, long)
*/
default ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Duration period) {
return scheduleAtFixedRate(task, period.toMillis());
}
代码示例来源:origin: apache/kafka
/**
* Get a timer which is bound to this time instance and expires after the given timeout
*/
default Timer timer(Duration timeout) {
return timer(timeout.toMillis());
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Schedule the given {@link Runnable}, invoking it at the specified execution time
* and subsequently with the given period.
* <p>Execution will end once the scheduler shuts down or the returned
* {@link ScheduledFuture} gets cancelled.
* @param task the Runnable to execute whenever the trigger fires
* @param startTime the desired first execution time for the task
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
* @param period the interval between successive executions of the task
* @return a {@link ScheduledFuture} representing pending completion of the task
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
* @since 5.0
* @see #scheduleAtFixedRate(Runnable, Date, long)
*/
default ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Instant startTime, Duration period) {
return scheduleAtFixedRate(task, Date.from(startTime), period.toMillis());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Schedule the given {@link Runnable}, invoking it at the specified execution time
* and subsequently with the given delay between the completion of one execution
* and the start of the next.
* <p>Execution will end once the scheduler shuts down or the returned
* {@link ScheduledFuture} gets cancelled.
* @param task the Runnable to execute whenever the trigger fires
* @param startTime the desired first execution time for the task
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
* @param delay the delay between the completion of one execution and the start of the next
* @return a {@link ScheduledFuture} representing pending completion of the task
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
* @since 5.0
* @see #scheduleWithFixedDelay(Runnable, Date, long)
*/
default ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Instant startTime, Duration delay) {
return scheduleWithFixedDelay(task, Date.from(startTime), delay.toMillis());
}
代码示例来源:origin: spring-projects/spring-framework
private static long parseDelayAsLong(String value) throws RuntimeException {
if (value.length() > 1 && (isP(value.charAt(0)) || isP(value.charAt(1)))) {
return Duration.parse(value).toMillis();
}
return Long.parseLong(value);
}
代码示例来源:origin: neo4j/neo4j
public LockManagerImpl( RagManager ragManager, Config config, Clock clock )
{
this.ragManager = ragManager;
this.clock = clock;
this.lockAcquisitionTimeoutMillis = config.get( GraphDatabaseSettings.lock_acquisition_timeout ).toMillis();
}
代码示例来源:origin: square/okhttp
/**
* Sets the default connect timeout for new connections. A value of 0 means no timeout,
* otherwise values must be between 1 and {@link Integer#MAX_VALUE} when converted to
* milliseconds.
*
* <p>The connect timeout is applied when connecting a TCP socket to the target host.
* The default value is 10 seconds.
*/
@IgnoreJRERequirement
public Builder connectTimeout(Duration duration) {
connectTimeout = checkDuration("timeout", duration.toMillis(), TimeUnit.MILLISECONDS);
return this;
}
代码示例来源:origin: square/okhttp
/**
* Sets the default write timeout for new connections. A value of 0 means no timeout, otherwise
* values must be between 1 and {@link Integer#MAX_VALUE} when converted to milliseconds.
*
* <p>The write timeout is applied for individual write IO operations.
* The default value is 10 seconds.
*
* @see Sink#timeout()
*/
@IgnoreJRERequirement
public Builder writeTimeout(Duration duration) {
writeTimeout = checkDuration("timeout", duration.toMillis(), TimeUnit.MILLISECONDS);
return this;
}
代码示例来源:origin: square/okhttp
/**
* Sets the default timeout for complete calls. A value of 0 means no timeout, otherwise values
* must be between 1 and {@link Integer#MAX_VALUE} when converted to milliseconds.
*
* <p>The call timeout spans the entire call: resolving DNS, connecting, writing the request
* body, server processing, and reading the response body. If the call requires redirects or
* retries all must complete within one timeout period.
*
* <p>The default value is 0 which imposes no timeout.
*/
@IgnoreJRERequirement
public Builder callTimeout(Duration duration) {
callTimeout = checkDuration("timeout", duration.toMillis(), TimeUnit.MILLISECONDS);
return this;
}
代码示例来源:origin: square/okhttp
/**
* Sets the default read timeout for new connections. A value of 0 means no timeout, otherwise
* values must be between 1 and {@link Integer#MAX_VALUE} when converted to milliseconds.
*
* <p>The read timeout is applied to both the TCP socket and for individual read IO operations
* including on {@link Source} of the {@link Response}. The default value is 10 seconds.
*
* @see Socket#setSoTimeout(int)
* @see Source#timeout()
*/
@IgnoreJRERequirement
public Builder readTimeout(Duration duration) {
readTimeout = checkDuration("timeout", duration.toMillis(), TimeUnit.MILLISECONDS);
return this;
}
代码示例来源:origin: square/okhttp
/**
* Sets the interval between HTTP/2 and web socket pings initiated by this client. Use this to
* automatically send ping frames until either the connection fails or it is closed. This keeps
* the connection alive and may detect connectivity failures.
*
* <p>If the server does not respond to each ping with a pong within {@code interval}, this
* client will assume that connectivity has been lost. When this happens on a web socket the
* connection is canceled and its listener is {@linkplain WebSocketListener#onFailure notified
* of the failure}. When it happens on an HTTP/2 connection the connection is closed and any
* calls it is carrying {@linkplain java.io.IOException will fail with an IOException}.
*
* <p>The default value of 0 disables client-initiated pings.
*/
@IgnoreJRERequirement
public Builder pingInterval(Duration duration) {
pingInterval = checkDuration("timeout", duration.toMillis(), TimeUnit.MILLISECONDS);
return this;
}
代码示例来源:origin: org.springframework/spring-context
private static long parseDelayAsLong(String value) throws RuntimeException {
if (value.length() > 1 && (isP(value.charAt(0)) || isP(value.charAt(1)))) {
return Duration.parse(value).toMillis();
}
return Long.parseLong(value);
}
代码示例来源:origin: apache/flink
private void tryAcquire() throws InterruptedException, TimeoutException {
if (!semaphore.tryAcquire(config.getMaxConcurrentRequestsTimeout().toMillis(), TimeUnit.MILLISECONDS)) {
throw new TimeoutException(
String.format(
"Failed to acquire 1 permit of %d to send value in %s.",
config.getMaxConcurrentRequests(),
config.getMaxConcurrentRequestsTimeout()
)
);
}
}
代码示例来源:origin: apache/flink
private void waitForJobTermination(
final RestClusterClient<ApplicationId> restClusterClient,
final JobID jobId) throws Exception {
stopJobSignal.signal();
final CompletableFuture<JobResult> jobResult = restClusterClient.requestJobResult(jobId);
jobResult.get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
}
代码示例来源:origin: apache/flink
protected static void waitUntilCondition(SupplierWithException<Boolean, Exception> condition, Deadline timeout) throws Exception {
while (timeout.hasTimeLeft() && !condition.get()) {
Thread.sleep(Math.min(RETRY_TIMEOUT, timeout.timeLeft().toMillis()));
}
if (!timeout.hasTimeLeft()) {
throw new TimeoutException("Condition was not met in given timeout.");
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldWaitForRequestedVersion() throws Exception
{
// given
long version = 5L;
// when
transactionIdTracker.awaitUpToDate( version, DEFAULT_DURATION );
// then
verify( transactionIdStore ).awaitClosedTransactionId( version, DEFAULT_DURATION.toMillis() );
}
代码示例来源:origin: neo4j/neo4j
@Test
void shouldParseTransactionTimeoutCorrectly() throws Throwable
{
// Given
Map<String,Object> msgMetadata = map( "tx_timeout", 123456L );
MapValue meta = ValueUtils.asMapValue( msgMetadata );
// When
RunMessage runMessage = new RunMessage( "RETURN 1", EMPTY_MAP, meta );
// Then
assertThat( runMessage.transactionTimeout().toMillis(), equalTo( 123456L ) );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
void hasDefaultBookmarkAwaitTimeout()
{
Config config = Config.defaults();
long bookmarkReadyTimeoutMs = config.get( GraphDatabaseSettings.bookmark_ready_timeout ).toMillis();
assertEquals( TimeUnit.SECONDS.toMillis( 30 ), bookmarkReadyTimeoutMs );
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void maxAge() {
Duration maxAge = Duration.ofDays(365);
String expires = HttpHeaders.formatDate(System.currentTimeMillis() + maxAge.toMillis());
expires = expires.substring(0, expires.indexOf(":") + 1);
assertThat(ResponseCookie.from("id", "1fWa").maxAge(maxAge).build().toString(), allOf(
startsWith("id=1fWa; Max-Age=31536000; Expires=" + expires),
endsWith(" GMT")));
assertThat(ResponseCookie.from("id", "1fWa").maxAge(maxAge.getSeconds()).build().toString(), allOf(
startsWith("id=1fWa; Max-Age=31536000; Expires=" + expires),
endsWith(" GMT")));
}
内容来源于网络,如有侵权,请联系作者删除!