Here you can find the source of sleepUntil(long time)
Parameter | Description |
---|---|
time | the long time in milliseconds to sleep until |
public static boolean sleepUntil(long time)
//package com.java2s; /* ******************************************************************* * Copyright (c) 1999-2001 Xerox Corporation, * 2002 Palo Alto Research Center, Incorporated (PARC). * All rights reserved. /* w w w . jav a 2s . c o m*/ * This program and the accompanying materials are made available * under the terms of the Eclipse Public License v1.0 * which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Xerox/PARC initial implementation * ******************************************************************/ public class Main { /** * Sleep until a particular time. * * @param time the long time in milliseconds to sleep until * @return true if delay succeeded, false if interrupted 100 times */ public static boolean sleepUntil(long time) { if (time == 0) { return true; } else if (time < 0) { throw new IllegalArgumentException("negative: " + time); } // final Thread thread = Thread.currentThread(); long curTime = System.currentTimeMillis(); for (int i = 0; (i < 100) && (curTime < time); i++) { try { Thread.sleep(time - curTime); } catch (InterruptedException e) { // ignore } curTime = System.currentTimeMillis(); } return (curTime >= time); } }