java.time.Instant.plusMillis()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(146)

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

Instant.plusMillis介绍

[英]Returns a copy of this instant with the specified duration in milliseconds added.

This instance is immutable and unaffected by this method call.
[中]返回添加了指定持续时间(毫秒)的此瞬间的副本。
此实例是不可变的,不受此方法调用的影响。

代码示例

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

@Inject
public Round(Role role)
{
  this.roundRole = role;
  this.roundStartTime = Instant.now().plusMillis(1200);
}

代码示例来源:origin: codecentric/spring-boot-admin

private NotificationFilter createFilter(@Nullable InstanceId id, String name, @Nullable Long ttl) {
    Instant expiry = ttl != null && ttl >= 0 ? Instant.now().plusMillis(ttl) : null;
    if (id != null) {
      return new InstanceIdNotificationFilter(id, expiry);
    } else {
      return new ApplicationNameNotificationFilter(name, expiry);
    }
  }
}

代码示例来源:origin: rubenlagus/TelegramBots

public RestrictChatMember forTimePeriod(Duration duration) {
  return setUntilDate(Instant.now().plusMillis(duration.toMillis()));
}

代码示例来源:origin: rubenlagus/TelegramBots

public KickChatMember forTimePeriod(Duration duration) {
  return setUntilDate(Instant.now().plusMillis(duration.toMillis()));
}

代码示例来源:origin: oracle/opengrok

private void addMessage(final AcceptedMessage acceptedMessage) {
  boolean added = false;
  for (String tag : acceptedMessage.getMessage().getTags()) {
    if (!tagMessages.containsKey(tag)) {
      tagMessages.put(tag, new TreeSet<>());
    }
    if (tagMessages.get(tag).add(acceptedMessage)) {
      messagesInTheSystem++;
      added = true;
    }
  }
  if (added && expirationTimer != null) {
    expirationTimer.schedule(new TimerTask() {
      @Override
      public void run() {
        expireMessages();
      }
    }, Date.from(acceptedMessage.getExpirationTime().plusMillis(10)));
  }
}

代码示例来源:origin: thinkaurelius/titan

@Override
public Instant sleepPast(Instant futureTime) throws InterruptedException {
  Instant now;
  ChronoUnit unit = getUnit();
  /*
   * Distributed storage managers that rely on timestamps play with the
   * least significant bit in timestamp longs, turning it on or off to
   * ensure that deletions are logically ordered before additions within a
   * single batch mutation. This is not a problem at microsecond
   * resolution because we pretendulate microsecond resolution by
   * multiplying currentTimeMillis by 1000, so the LSB can vary freely.
   * It's also not a problem with nanosecond resolution because the
   * resolution is just too fine, relative to how long a mutation takes,
   * for it to matter in practice. But it can lead to corruption at
   * millisecond resolution (and does, in testing).
   */
  if (unit.equals(TimeUnit.MILLISECONDS))
    futureTime = futureTime.plusMillis(1L);
  while ((now = getTime()).compareTo(futureTime) <= 0) {
    long delta = getTime(futureTime) - getTime(now);
    if (0L == delta)
      delta = 1L;
    if (log.isTraceEnabled()) {
      log.trace("Sleeping: now={} targettime={} delta={} {}",
          new Object[] { now, futureTime, delta, unit });
    }
    Temporals.timeUnit(unit).sleep(delta);
  }
  return now;
}

代码示例来源:origin: JanusGraph/janusgraph

@Override
public Instant sleepPast(Instant futureTime) throws InterruptedException {
  Instant now;
  ChronoUnit unit = getUnit();
  /*
   * Distributed storage managers that rely on timestamps play with the
   * least significant bit in timestamp longs, turning it on or off to
   * ensure that deletions are logically ordered before additions within a
   * single batch mutation. This is not a problem at microsecond
   * resolution because we pretend to have microsecond resolution by
   * multiplying currentTimeMillis by 1000, so the LSB can vary freely.
   * It's also not a problem with nanosecond resolution because the
   * resolution is just too fine, relative to how long a mutation takes,
   * for it to matter in practice. But it can lead to corruption at
   * millisecond resolution (and does, in testing).
   */
  if (unit.equals(ChronoUnit.MILLIS))
    futureTime = futureTime.plusMillis(1L);
  while ((now = getTime()).compareTo(futureTime) <= 0) {
    long delta = getTime(futureTime) - getTime(now);
    if (0L == delta)
      delta = 1L;
    if (log.isTraceEnabled()) {
      log.trace("Sleeping: now={} targettime={} delta={} {}", now, futureTime, delta, unit);
    }
    Temporals.timeUnit(unit).sleep(delta);
  }
  return now;
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

@Test
public void testReadingDocumentWithFirstAMoveWithEpoch() {
  Instant hourly = Instant.parse("2018-02-12T00:59:59.999Z");
  Instant minutely = Instant.parse("2018-02-12T00:00:59.999Z");
  Date epochHourlyFirstCycle = Date.from(hourly);
  Date epochMinutelyFirstCycle = Date.from(minutely);
  Date epochHourlySecondCycle = Date.from(hourly.plusMillis(1));
  Date epochMinutelySecondCycle = Date.from(minutely.plusMillis(1));
  doTestEpochMove(epochHourlyFirstCycle.getTime(), RollCycles.MINUTELY);
  doTestEpochMove(epochHourlySecondCycle.getTime(), RollCycles.MINUTELY);
  doTestEpochMove(epochHourlyFirstCycle.getTime(), RollCycles.HOURLY);
  doTestEpochMove(epochHourlySecondCycle.getTime(), RollCycles.HOURLY);
  doTestEpochMove(epochHourlyFirstCycle.getTime(), RollCycles.DAILY);
  doTestEpochMove(epochHourlySecondCycle.getTime(), RollCycles.DAILY);
  doTestEpochMove(epochMinutelyFirstCycle.getTime(), RollCycles.MINUTELY);
  doTestEpochMove(epochMinutelySecondCycle.getTime(), RollCycles.MINUTELY);
  doTestEpochMove(epochMinutelyFirstCycle.getTime(), RollCycles.HOURLY);
  doTestEpochMove(epochMinutelySecondCycle.getTime(), RollCycles.HOURLY);
  doTestEpochMove(epochMinutelyFirstCycle.getTime(), RollCycles.DAILY);
  doTestEpochMove(epochMinutelySecondCycle.getTime(), RollCycles.DAILY);
}

代码示例来源:origin: eclipse/smarthome

protected void setInstant(Duration duration) {
    this.instant = Instant.now().plusMillis(duration.toMillis());
  }
}

代码示例来源:origin: spring-projects/spring-kafka

private void scheduleTimeout(ProducerRecord<K, V> record, CorrelationKey correlationId) {
  this.scheduler.schedule(() -> {
    RequestReplyFuture<K, V, R> removed = this.futures.remove(correlationId);
    if (removed != null) {
      if (this.logger.isWarnEnabled()) {
        this.logger.warn("Reply timed out for: " + record + WITH_CORRELATION_ID + correlationId);
      }
      removed.setException(new KafkaException("Reply timed out"));
    }
  }, Instant.now().plusMillis(this.replyTimeout));
}

代码示例来源:origin: sixt/ja-micro

@Test
  public void offsetGetsCommitted() throws Exception {
    committer.offsetCommitted(Collections.singletonMap(new TopicPartition("a", 1),
        new OffsetAndMetadata(333L)));
    committer.recommitOffsets();
    verifyNoMoreInteractions(consumer);
    when(clock.instant()).thenReturn(Instant.now().plus(OffsetCommitter.IDLE_DURATION).plusMillis(1000));
    committer.recommitOffsets();
    //now it's time to work...
    verify(consumer, times(1)).commitSync(any(Map.class));
  }
}

代码示例来源:origin: sixt/ja-micro

@Test
public void partitionsAssigned() throws Exception {
  List<TopicPartition> partitions = new ArrayList<>();
  TopicPartition topicA = new TopicPartition("a", 1);
  TopicPartition topicB = new TopicPartition("b", 2);
  partitions.add(topicA);
  partitions.add(topicB);
  when(consumer.position(topicA)).thenReturn(42L);
  when(consumer.position(topicB)).thenReturn(43L);
  committer.partitionsAssigned(partitions);
  committer.recommitOffsets();
  verify(consumer, times(2)).position(any(TopicPartition.class));
  //it's not time to work yet
  verifyNoMoreInteractions(consumer);
  when(clock.instant()).thenReturn(Instant.now().plus(OffsetCommitter.IDLE_DURATION).plusMillis(1000));
  committer.recommitOffsets();
  //now it's time to work...
  verify(consumer, times(2)).commitSync(any(Map.class));
  committer.partitionsRevoked(partitions);
  assertThat(committer.offsetData).isEmpty();
}

代码示例来源:origin: UniversaBlockchain/universa

public void updateNextRetransmitTime() {
    int maxRetransmitDelay = RETRANSMIT_TIME_GROW_FACTOR*retransmitCounter + RETRANSMIT_MAX_ATTEMPTS;
    maxRetransmitDelay /= RETRANSMIT_MAX_ATTEMPTS;
    maxRetransmitDelay *= RETRANSMIT_TIME;
    maxRetransmitDelay += RETRANSMIT_TIME/2;
    nextRetransmitTime = Instant.now().plusMillis(new Random().nextInt(maxRetransmitDelay));
  }
}

代码示例来源:origin: Baqend/Orestes-Bloomfilter

/**
 * Converts a desired unit to the score stored in Redis.
 *
 * @param TTL  the TTL to convert
 * @param unit the unit of the TTL
 * @return timestamp from TTL in microseconds
 */
private long remainingTTLToScore(long TTL, TimeUnit unit) {
  return clock.instant().plusMillis(MILLISECONDS.convert(TTL, unit)).toEpochMilli();
}

代码示例来源:origin: Baqend/Orestes-Bloomfilter

public long putRemaining(T key, long value, TimeUnit timeUnit) {
  long absoluteValue = clock.instant().plusMillis(MILLISECONDS.convert(value, timeUnit)).toEpochMilli();
  return compute(key, (item, oldValue) -> oldValue == null ? absoluteValue : Math.max(oldValue, absoluteValue));
}

代码示例来源:origin: spotify/styx

private boolean shouldExecute(RunState runState) {
 if (runState.state() != State.QUEUED) {
  return false;
 }
 final Instant now = time.get();
 final Instant deadline = Instant
   .ofEpochMilli(runState.timestamp())
   .plusMillis(runState.data().retryDelayMillis().orElse(0L));
 return !deadline.isAfter(now);
}

代码示例来源:origin: sakaiproject/sakai

@Override
public void triggerComplete(Trigger trigger, JobExecutionContext context, CompletedExecutionInstruction triggerInstructionCode) {
  Date complete = Date.from(context.getFireTime().toInstant().plusMillis(context.getJobRunTime()));
  eventManager.createTriggerEvent (TriggerEvent.TRIGGER_EVENT_TYPE.COMPLETE, context.getJobDetail().getKey(), trigger.getKey(), complete, "Trigger complete", getServerId());
}

代码示例来源:origin: isopropylcyanide/Jwt-Spring-Security-JPA

/**
 * Creates and returns a new password token to which a user must be associated
 */
public PasswordResetToken createToken() {
  PasswordResetToken passwordResetToken = new PasswordResetToken();
  String token = Util.generateRandomUuid();
  passwordResetToken.setToken(token);
  passwordResetToken.setExpiryDate(Instant.now().plusMillis(expiration));
  return passwordResetToken;
}

代码示例来源:origin: org.sakaiproject.scheduler/scheduler-component-shared

@Override
public void triggerComplete(Trigger trigger, JobExecutionContext context, CompletedExecutionInstruction triggerInstructionCode) {
  Date complete = Date.from(context.getFireTime().toInstant().plusMillis(context.getJobRunTime()));
  eventManager.createTriggerEvent (TriggerEvent.TRIGGER_EVENT_TYPE.COMPLETE, context.getJobDetail().getKey(), trigger.getKey(), complete, "Trigger complete", getServerId());
}

代码示例来源:origin: com.atlassian.jira/jira-core

@Override
public void start() throws Exception
{
  final SchedulerService scheduler = ComponentAccessor.getComponent(SchedulerService.class);
  scheduler.registerJobRunner(JOB_RUNNER_KEY, this);
  // we need to scatter a bit sending events to analytics system,
  // lets not start this service on every instance in the same moment
  final Date firstRun = Date.from(Instant.now().plusMillis(random.nextLong() % FOUR_HOURS));
  final JobConfig jobConfig = JobConfig.forJobRunnerKey(JOB_RUNNER_KEY)
      .withRunMode(RunMode.RUN_LOCALLY)
      .withSchedule(Schedule.forInterval(RUN_INTERVAL, firstRun));
  scheduler.scheduleJob(JOB_ID, jobConfig);
}

相关文章