Here you can find the source of sleepFixed(int milliSecond)
Parameter | Description |
---|---|
milliSecond | milliSecond time to sleep in millisecond |
public static void sleepFixed(int milliSecond)
//package com.java2s; //License from project: Open Source License public class Main { /**/*www . j a va 2 s .c o m*/ * Put the calling thread to sleep. * Note, this thread does not throw interrupted exception, * and will not return until the thread has slept for provided time. * * @param milliSecond milliSecond time to sleep in millisecond */ public static void sleepFixed(int milliSecond) { final long endingTime = System.currentTimeMillis() + milliSecond; long remainingTime = milliSecond; while (remainingTime > 0) { try { Thread.sleep(remainingTime); } catch (InterruptedException ignore) { } remainingTime = endingTime - System.currentTimeMillis(); } } /** * Put the calling thread to sleep. * Note, this thread does not throw interrupted exception, * but may return prematurely as a result of one. * * @param milliSecond time to sleep in millisecond */ public static void sleep(int milliSecond) { try { Thread.sleep(milliSecond); } catch (InterruptedException ignore) { } } }