Java LocalDateTime Calculate sleepUntil(LocalDateTime next)

Here you can find the source of sleepUntil(LocalDateTime next)

Description

sleep Until

License

Apache License

Declaration

public static void sleepUntil(LocalDateTime next) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

import java.util.logging.Logger;

public class Main {
    private static final Logger LOGGER = Logger.getGlobal();

    public static void sleepUntil(LocalDateTime next) {
        while (true) {
            try {
                LocalDateTime now = LocalDateTime.now();
                long intervalInMillis = now.until(next, ChronoUnit.MILLIS);
                if (intervalInMillis > 0) {
                    Thread.sleep(intervalInMillis);
                }//from  w ww. j a v  a2  s  .  c o  m
                return;
            } catch (InterruptedException e) {
                LOGGER.fine("sleeping interrupted. resuming to sleep ...");
            }
        }
    }
}

Related

  1. safeCreateFromValue(LocalDateTime datetime, int year, int month, int day, int hour, int minute, int second)
  2. secondsBetween(LocalDateTime date1, LocalDateTime date2)
  3. setTime(LocalDateTime source, String time)
  4. shiftDateTime(String timex, LocalDateTime reference, boolean future)
  5. shouldSend(Optional emailSentOpt, int timeToWait)
  6. toCalendar(final LocalDateTime localDateTime)
  7. toOffsetDateTime(Date localDateTime, TimeZone clientTimeZone)
  8. WizzAirDatetimeCorrection(LocalDateTime aLocalDateTime)