Here you can find the source of sleepUntil(LocalDateTime next)
public static void sleepUntil(LocalDateTime next)
//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 ..."); } } } }