Here you can find the source of delayUntilNextSecond(int millis)
static void delayUntilNextSecond(int millis)
//package com.java2s; /**/*from w w w . ja v a 2s .c o m*/ * Logback: the reliable, generic, fast and flexible logging framework. * Copyright (C) 1999-2009, QOS.ch. All rights reserved. * * This program and the accompanying materials are dual-licensed under * either the terms of the Eclipse Public License v1.0 as published by * the Eclipse Foundation * * or (per the licensee's choosing) * * under the terms of the GNU Lesser General Public License version 2.1 * as published by the Free Software Foundation. */ import java.util.Calendar; import java.util.Date; public class Main { static void delayUntilNextSecond(int millis) { long now = System.currentTimeMillis(); Calendar cal = Calendar.getInstance(); cal.setTime(new Date(now)); cal.set(Calendar.MILLISECOND, millis); cal.add(Calendar.SECOND, 1); long next = cal.getTime().getTime(); try { Thread.sleep(next - now); } catch (Exception e) { } } }