All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.shoothzj.javatool.util.CommonUtil Maven / Gradle / Ivy

There is a newer version: 3.1.15
Show newest version
package com.github.shoothzj.javatool.util;

import java.util.concurrent.TimeUnit;

/**
 * @author hezhangjian
 */
public class CommonUtil {
    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(CommonUtil.class);

    public static void sleep(TimeUnit timeUnit, int timeout) {
        try {
            switch (timeUnit) {
            case DAYS: 
                TimeUnit.DAYS.sleep(timeout);
                break;
            case HOURS: 
                TimeUnit.HOURS.sleep(timeout);
                break;
            case MINUTES: 
                TimeUnit.MINUTES.sleep(timeout);
                break;
            case SECONDS: 
                TimeUnit.SECONDS.sleep(timeout);
                break;
            case MILLISECONDS: 
                TimeUnit.MILLISECONDS.sleep(timeout);
                break;
            case MICROSECONDS: 
                TimeUnit.MICROSECONDS.sleep(timeout);
                break;
            case NANOSECONDS: 
                TimeUnit.NANOSECONDS.sleep(timeout);
                break;
            default: 
                log.info("do nothing");
                break;
            }
        } catch (InterruptedException e) {
            log.error("Do nothing, exception is {}", ExceptionUtil.getException(e));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy