本文整理了Java中java.time.Duration.toNanos()
方法的一些代码示例,展示了Duration.toNanos()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Duration.toNanos()
方法的具体详情如下:
包路径:java.time.Duration
类名称:Duration
方法名:toNanos
[英]Converts this duration to the total length in nanoseconds expressed as a long.
If this duration is too large to fit in a long nanoseconds, then an exception is thrown.
[中]
代码示例来源:origin: hibernate/hibernate-orm
@Override
public String toString(Duration value) {
if ( value == null ) {
return null;
}
return String.valueOf( value.toNanos() );
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
public String objectToSQLString(Duration value, Dialect dialect) throws Exception {
return String.valueOf( value.toNanos() );
}
代码示例来源:origin: neo4j/neo4j
public VmPauseMonitor( Duration measureInterval, Duration stallAlertThreshold, Log log, JobScheduler jobScheduler, Consumer<VmPauseInfo> listener )
{
this.measurementDurationNs = requirePositive( measureInterval.toNanos() );
this.stallAlertThresholdNs = requireNonNegative( stallAlertThreshold.toNanos() );
this.log = requireNonNull( log );
this.jobScheduler = requireNonNull( jobScheduler );
this.listener = requireNonNull( listener );
}
代码示例来源:origin: thinkaurelius/titan
public StandardLockCleanerService(KeyColumnValueStore store, ConsistentKeyLockerSerializer serializer, ExecutorService exec, Duration cooldown, TimestampProvider times) {
this.store = store;
this.serializer = serializer;
this.exec = exec;
this.times = times;
blocked = CacheBuilder.newBuilder()
.expireAfterWrite(cooldown.toNanos(), TimeUnit.NANOSECONDS)
.concurrencyLevel(COOLDOWN_CONCURRENCY_LEVEL)
.<KeyColumn, Instant>build()
.asMap();
}
代码示例来源:origin: thinkaurelius/titan
@Override
public void sleepFor(Duration duration) throws InterruptedException {
if (duration.isZero()) return;
TimeUnit.NANOSECONDS.sleep(duration.toNanos());
}
代码示例来源:origin: neo4j/neo4j
public FakeClock forward( Duration delta )
{
return forward( delta.toNanos(), TimeUnit.NANOSECONDS );
}
代码示例来源:origin: thinkaurelius/titan
@Override
public void lock(Duration timeout) {
boolean success = false;
try {
success = super.tryLock(timeout.toNanos(), TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
log.warn("Interrupted waiting for lock: {}",e);
}
if (!success) throw new TitanException("Possible dead lock detected. Waited for transaction lock without success");
}
代码示例来源:origin: thinkaurelius/titan
@Override
protected void waitCondition() throws InterruptedException {
MessageEnvelope msg = outgoingMsg.poll(maxWaitTime().toNanos(), TimeUnit.NANOSECONDS);
if (msg!=null) toSend.add(msg);
}
代码示例来源:origin: apache/flink
/**
* Constructs a Deadline that is a given duration after now.
*/
public static Deadline fromNow(Duration duration) {
return new Deadline(Math.addExact(System.nanoTime(), duration.toNanos()));
}
}
代码示例来源:origin: google/guava
/**
* Specifies that each entry should be automatically removed from the cache once a fixed duration
* has elapsed after the entry's creation, or the most recent replacement of its value.
*
* <p>When {@code duration} is zero, this method hands off to {@link #maximumSize(long)
* maximumSize}{@code (0)}, ignoring any otherwise-specified maximum size or weight. This can be
* useful in testing, or to disable caching temporarily without a code change.
*
* <p>Expired entries may be counted in {@link Cache#size}, but will never be visible to read or
* write operations. Expired entries are cleaned up as part of the routine maintenance described
* in the class javadoc.
*
* @param duration the length of time after an entry is created that it should be automatically
* removed
* @return this {@code CacheBuilder} instance (for chaining)
* @throws IllegalArgumentException if {@code duration} is negative
* @throws IllegalStateException if the time to live or time to idle was already set
* @throws ArithmeticException for durations greater than +/- approximately 292 years
* @since 25.0
*/
@J2ObjCIncompatible
@GwtIncompatible // java.time.Duration
public CacheBuilder<K, V> expireAfterWrite(java.time.Duration duration) {
return expireAfterWrite(duration.toNanos(), TimeUnit.NANOSECONDS);
}
代码示例来源:origin: google/guava
/**
* Specifies that each entry should be automatically removed from the cache once a fixed duration
* has elapsed after the entry's creation, the most recent replacement of its value, or its last
* access. Access time is reset by all cache read and write operations (including {@code
* Cache.asMap().get(Object)} and {@code Cache.asMap().put(K, V)}), but not by operations on the
* collection-views of {@link Cache#asMap}.
*
* <p>When {@code duration} is zero, this method hands off to {@link #maximumSize(long)
* maximumSize}{@code (0)}, ignoring any otherwise-specified maximum size or weight. This can be
* useful in testing, or to disable caching temporarily without a code change.
*
* <p>Expired entries may be counted in {@link Cache#size}, but will never be visible to read or
* write operations. Expired entries are cleaned up as part of the routine maintenance described
* in the class javadoc.
*
* @param duration the length of time after an entry is last accessed that it should be
* automatically removed
* @return this {@code CacheBuilder} instance (for chaining)
* @throws IllegalArgumentException if {@code duration} is negative
* @throws IllegalStateException if the time to idle or time to live was already set
* @throws ArithmeticException for durations greater than +/- approximately 292 years
* @since 25.0
*/
@J2ObjCIncompatible
@GwtIncompatible // java.time.Duration
public CacheBuilder<K, V> expireAfterAccess(java.time.Duration duration) {
return expireAfterAccess(duration.toNanos(), TimeUnit.NANOSECONDS);
}
代码示例来源:origin: ben-manes/caffeine
/**
* Specifies that each entry should be automatically removed from the cache once a fixed
* duration has elapsed. The expiration policy determines when the entry's age is reset.
*
* @param duration the length of time after which an entry should be automatically removed
* @throws IllegalArgumentException if {@code duration} is negative
*/
default void setExpiresAfter(@NonNull Duration duration) {
// This method will be abstract in version 3.0.0
setExpiresAfter(duration.toNanos(), TimeUnit.NANOSECONDS);
}
代码示例来源:origin: apache/flink
public Deadline plus(Duration other) {
return new Deadline(Math.addExact(timeNanos, other.toNanos()));
}
代码示例来源:origin: ben-manes/caffeine
/**
* Specifies that the entry should be automatically removed from the cache once the duration has
* elapsed. The expiration policy determines when the entry's age is reset.
*
* @param key the key for the entry being set
* @param duration the length of time from now when the entry should be automatically removed
* @throws IllegalArgumentException if {@code duration} is negative
*/
default void setExpiresAfter(@NonNull K key, @NonNull Duration duration) {
// This method will be abstract in version 3.0.0
setExpiresAfter(key, duration.toNanos(), TimeUnit.NANOSECONDS);
}
代码示例来源:origin: google/guava
return refreshAfterWrite(duration.toNanos(), TimeUnit.NANOSECONDS);
代码示例来源:origin: resilience4j/resilience4j
private void markSuccess() {
if (wasCallPermitted()) {
circuitBreaker.onSuccess(stopWatch.stop().getProcessingDuration().toNanos());
}
}
代码示例来源:origin: ben-manes/caffeine
/**
* Associates the {@code value} with the {@code key} in this cache. If the cache previously
* contained a value associated with the {@code key}, the old value is replaced by the new
* {@code value}. This method differs from {@link Cache#put} by substituting the
* configured {@link Expiry} with the specified write duration.
*
* @param key the key with which the specified value is to be associated
* @param value value to be associated with the specified key
* @param duration the length of time from now when the entry should be automatically removed
* @throws IllegalArgumentException if {@code duration} is negative
*/
default void put(@NonNull K key, @NonNull V value, @NonNull Duration duration) {
// This method will be abstract in version 3.0.0
put(key, value, duration.toNanos(), TimeUnit.NANOSECONDS);
}
代码示例来源:origin: resilience4j/resilience4j
private void markSuccess() {
if (wasCallPermitted()) {
circuitBreaker.onSuccess(stopWatch.stop().getProcessingDuration().toNanos());
}
}
}
代码示例来源:origin: neo4j/neo4j
@Test
void shouldConvertNanosOfDayToUTC()
{
int nanosOfDayLocal = 42;
Duration offsetDuration = Duration.ofMinutes( 35 );
long nanosOfDayUTC = TemporalUtil.nanosOfDayToUTC( nanosOfDayLocal, (int) offsetDuration.getSeconds() );
assertEquals( nanosOfDayLocal - offsetDuration.toNanos(), nanosOfDayUTC );
}
代码示例来源:origin: neo4j/neo4j
@Test
void shouldGetNanosOfDayUTC()
{
LocalTime localTime = LocalTime.of( 14, 19, 18, 123999 );
ZoneOffset offset = ZoneOffset.ofHours( -12 );
OffsetTime time = OffsetTime.of( localTime, offset );
long nanosOfDayUTC = TemporalUtil.getNanosOfDayUTC( time );
long expectedNanosOfDayUTC = Duration.ofSeconds( localTime.toSecondOfDay() )
.minus( offset.getTotalSeconds(), SECONDS )
.toNanos();
assertEquals( expectedNanosOfDayUTC + localTime.getNano(), nanosOfDayUTC );
}
}
内容来源于网络,如有侵权,请联系作者删除!