java.time.Clock.tick()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(2.1k)|赞(0)|评价(0)|浏览(163)

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

Clock.tick介绍

[英]Obtains a clock that returns instants from the specified clock truncated to the nearest occurrence of the specified duration.

This clock will only tick as per the specified duration. Thus, if the duration is half a second, the clock will return instants truncated to the half second.

The tick duration must be positive. If it has a part smaller than a whole millisecond, then the whole duration must divide into one second without leaving a remainder. All normal tick durations will match these criteria, including any multiple of hours, minutes, seconds and milliseconds, and sensible nanosecond durations, such as 20ns, 250,000ns and 500,000ns.

A duration of zero or one nanosecond would have no truncation effect. Passing one of these will return the underlying clock.

Implementations may use a caching strategy for performance reasons. As such, it is possible that the start of the requested duration observed via this clock will be later than that observed directly via the underlying clock.

The returned implementation is immutable, thread-safe and Serializableproviding that the base clock is.
[中]获取一个时钟,该时钟返回从指定的时钟截断到指定持续时间内最近的事件的实例。
此时钟将仅按照指定的持续时间滴答作响。因此,如果持续时间为半秒,时钟将返回被截断为半秒的瞬间。
刻度持续时间必须为正。如果它的一部分小于一整毫秒,那么整个持续时间必须分为一秒而不留余数。所有正常滴答声持续时间都将符合这些标准,包括小时、分钟、秒和毫秒的任意倍数,以及合理的纳秒持续时间,如20ns、250000ns和500000ns。
零或一纳秒的持续时间不会产生截断效应。传递其中一个将返回基础时钟。
出于性能原因,实现可能会使用缓存策略。因此,通过该时钟观察到的请求持续时间的开始可能晚于通过基础时钟直接观察到的持续时间。
返回的实现是不可变的、线程安全的和可序列化的,前提是基本时钟为。

代码示例

代码示例来源:origin: EvoSuite/evosuite

public static Clock tick(Clock baseClock, Duration tickDuration) {
  return Clock.tick(baseClock, tickDuration);
}

代码示例来源:origin: de.ck35.monitoring/request-tagging-core

public void setCollectorSendDelayDuration(Duration collectorSendDelayDuration) {
  this.collectorSendDelayDuration = collectorSendDelayDuration;
  this.sendIntervalClock = Clock.tick(Clock.systemUTC(), this.collectorSendDelayDuration);
}

代码示例来源:origin: com.jtransc/jtransc-rt

public static Clock tickMinutes(ZoneId zone) {
  return tick(system(zone), Duration.ofMinutes(1));
}

代码示例来源:origin: com.jtransc/jtransc-rt

public static Clock tickSeconds(ZoneId zone) {
  return tick(system(zone), Duration.ofSeconds(1));
}

相关文章