package cn.axzo.msg.center.common.utils;

import java.util.concurrent.TimeUnit;

/**
 * @author yanglin
 */
public class MiscUtils {

    public static void sleepQuietly(long sleepTime, TimeUnit unit) {
        long deadline = System.currentTimeMillis() + unit.toMillis(sleepTime);
        long waitMs = deadline - System.currentTimeMillis();
        boolean isInterrupted = false;
        while (waitMs > 0) {
            try {
                Thread.sleep(waitMs);
            } catch (InterruptedException e) {
                isInterrupted = true;
            }
            waitMs = deadline - System.currentTimeMillis();
        }
        if (isInterrupted) {
            Thread.currentThread().interrupt();
        }
    }

}