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

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

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

Clock.millis介绍

[英]Gets the current millisecond instant of the clock.

This returns the millisecond-based instant, measured from 1970-01-01T00:00 UTC. This is equivalent to the definition of System#currentTimeMillis().

Most applications should avoid this method and use Instant to represent an instant on the time-line rather than a raw millisecond value. This method is provided to allow the use of the clock in high performance use cases where the creation of an object would be unacceptable. The default implementation currently calls #instant().
[中]获取时钟的当前毫秒瞬间。
这将返回基于毫秒的瞬间,从1970-01-01T00:00 UTC开始测量。这相当于System#currentTimeMillis()的定义。
大多数应用程序都应该避免这种方法,并使用Instant来表示时间线上的一个瞬间,而不是原始毫秒值。提供此方法是为了允许在无法接受对象创建的高性能用例中使用时钟。默认实现当前调用#instant()。

代码示例

代码示例来源:origin: neo4j/neo4j

private SuspendedTransaction( ActiveTransaction activeMarker, TransactionHandle transactionHandle )
{
  this.activeMarker = activeMarker;
  this.transactionHandle = transactionHandle;
  this.lastActiveTimestamp = clock.millis();
}

代码示例来源:origin: neo4j/neo4j

@Override
protected boolean thresholdReached( long lastCommittedTransactionId )
{
  return lastCommittedTransactionId > lastCheckPointedTransactionId &&
      clock.millis() >= nextCheckPointTime;
}

代码示例来源:origin: neo4j/neo4j

@Override
public void checkPointHappened( long transactionId )
{
  nextCheckPointTime = clock.millis() + timeMillisThreshold;
  lastCheckPointedTransactionId = transactionId;
}

代码示例来源:origin: neo4j/neo4j

@Override
public long nextCheckTime()
{
  return clock.millis() + intervalMillis;
}

代码示例来源:origin: neo4j/neo4j

@Override
public void init()
{
  lowerLimit = clock.millis() - timeToKeepInMillis;
}

代码示例来源:origin: neo4j/neo4j

private long currentTimeMillis()
{
  return clock.millis();
}

代码示例来源:origin: apache/flink

long elapsedTime(Clock clock) {
  return clock.millis() - transactionStartTime;
}

代码示例来源:origin: neo4j/neo4j

public void authFailed()
  {
    failedAuthAttempts.incrementAndGet();
    lastFailedAttemptTime = clock.millis();
  }
}

代码示例来源:origin: neo4j/neo4j

public boolean authenticationPermitted()
{
  return maxFailedAttempts <= 0 || // amount of attempts is not limited
      failedAuthAttempts.get() < maxFailedAttempts || // less failed attempts than configured
      clock.millis() >= lastFailedAttemptTime + lockDurationMs; // auth lock duration expired
}

代码示例来源:origin: neo4j/neo4j

TimeCheckPointThreshold( long thresholdMillis, Clock clock )
{
  super( "time threshold" );
  this.timeMillisThreshold = thresholdMillis;
  this.clock = clock;
  // The random start offset means database in a cluster will not all check-point at the same time.
  long randomStartOffset = thresholdMillis > 0 ? ThreadLocalRandom.current().nextLong( thresholdMillis ) : 0;
  this.nextCheckPointTime = clock.millis() + thresholdMillis + randomStartOffset;
}

代码示例来源:origin: neo4j/neo4j

private void awaitTransactionsClosedWithinTimeout()
  {
    long deadline = clock.millis() + awaitActiveTransactionDeadlineMillis;
    while ( transactionCounters.getNumberOfActiveTransactions() > 0 && clock.millis() < deadline )
    {
      parkNanos( MILLISECONDS.toNanos( 10 ) );
    }
  }
}

代码示例来源:origin: apache/flink

/**
 * This method must be the only place to call {@link #beginTransaction()} to ensure that the
 * {@link TransactionHolder} is created at the same time.
 */
private TransactionHolder<TXN> beginTransactionInternal() throws Exception {
  return new TransactionHolder<>(beginTransaction(), clock.millis());
}

代码示例来源:origin: neo4j/neo4j

@Override
public synchronized void run()
{
  long now = clock.millis();
  Set<KernelTransactionHandle> activeTransactions = kernelTransactions.activeTransactions();
  checkExpiredTransactions( activeTransactions, now );
}

代码示例来源:origin: neo4j/neo4j

@Override
  public void check( StageExecution execution )
  {
    long currentTimeMillis = clock.millis();
    for ( int i = 0; i < monitors.length; i++ )
    {
      if ( currentTimeMillis >= endTimes[i] )
      {
        monitors[i].check( execution );
        endTimes[i] = monitors[i].nextCheckTime();
      }
    }
  }
}

代码示例来源:origin: neo4j/neo4j

private EphemeralFileData( DynamicByteBuffer data, Clock clock )
{
  this.fileAsBuffer = data;
  this.forcedBuffer = data.copy();
  this.clock = clock;
  this.lastModified = clock.millis();
}

代码示例来源:origin: neo4j/neo4j

private void assertNotExpired( long timeBoundary )
{
  if ( lockAcquisitionTimeoutMillis > 0 )
  {
    if ( timeBoundary < clock.millis() )
    {
      throw new LockAcquisitionTimeoutException( resource.type(), resource.resourceId(),
          lockAcquisitionTimeoutMillis );
    }
  }
}

代码示例来源:origin: neo4j/neo4j

@Test
public void dontThrottleMethodsReturningVoid()
{
  when( clock.millis() ).thenReturn( 100L );
  proxy.returnVoid();
  proxy.returnVoid();
  verify( target, times( 2 ) ).returnVoid();
  verifyNoMoreInteractions( target );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void dontThrottleMethodsWithArgs()
{
  when( clock.millis() ).thenReturn( 100L );
  proxy.notGetter( 1 );
  proxy.notGetter( 2 );
  verify( target, times( 2 ) ).notGetter( anyLong() );
  verifyNoMoreInteractions( target );
}

代码示例来源:origin: neo4j/neo4j

private BoltStateMachineState processRunMessage( RunMessage message, StateMachineContext context ) throws KernelException
{
  long start = context.clock().millis();
  StatementProcessor statementProcessor = context.connectionState().getStatementProcessor();
  StatementMetadata statementMetadata = statementProcessor.run( message.statement(), message.params() );
  long end = context.clock().millis();
  context.connectionState().onMetadata( FIELDS_KEY, stringArray( statementMetadata.fieldNames() ) );
  context.connectionState().onMetadata( FIRST_RECORD_AVAILABLE_KEY, Values.longValue( end - start ) );
  return streamingState;
}

代码示例来源:origin: neo4j/neo4j

private BoltStateMachineState processRunMessage( RunMessage message, StateMachineContext context ) throws KernelException
{
  long start = context.clock().millis();
  StatementProcessor statementProcessor = context.connectionState().getStatementProcessor();
  StatementMetadata statementMetadata = statementProcessor.run( message.statement(), message.params(), message.bookmark(), message.transactionTimeout(),
      message.transactionMetadata() );
  long end = context.clock().millis();
  context.connectionState().onMetadata( FIELDS_KEY, stringArray( statementMetadata.fieldNames() ) );
  context.connectionState().onMetadata( FIRST_RECORD_AVAILABLE_KEY, Values.longValue( end - start ) );
  return streamingState;
}

相关文章