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

com.didiglobal.logi.job.utils.ThreadUtil Maven / Gradle / Ivy

There is a newer version: 1.0.31
Show newest version
package com.didiglobal.logi.job.utils;

import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * thread util.
 */
public class ThreadUtil {
    private static final Logger logger = LoggerFactory.getLogger(ThreadUtil.class);

    /**
     * sleep.
     *
     * @param time     time
     * @param timeUnit time unit
     */
    public static void sleep(long time, TimeUnit timeUnit) {
        try {
            switch (timeUnit) {
                case DAYS: {
                    TimeUnit.DAYS.sleep(time);
                    break;
                }
                case HOURS: {
                    TimeUnit.HOURS.sleep(time);
                    break;
                }
                case MINUTES: {
                    TimeUnit.MINUTES.sleep(time);
                    break;
                }
                case SECONDS: {
                    TimeUnit.SECONDS.sleep(time);
                    break;
                }
                case NANOSECONDS: {
                    TimeUnit.NANOSECONDS.sleep(time);
                    break;
                }
                case MICROSECONDS: {
                    TimeUnit.MICROSECONDS.sleep(time);
                    break;
                }
                case MILLISECONDS: {
                    TimeUnit.MILLISECONDS.sleep(time);
                    break;
                }
                default:
                    break;
            }
        } catch (InterruptedException e) {
            logger.error("class=ThreadUtil||method=sleep||url=||msg={}", e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy