定时器工具类

来源:互联网 发布:刚出土的兵马俑知乎 编辑:程序博客网 时间:2024/06/05 02:06
import java.util.concurrent.Executors;import java.util.concurrent.ScheduledExecutorService;import java.util.concurrent.ScheduledFuture;import java.util.concurrent.ThreadFactory;import java.util.concurrent.TimeUnit;/** * 类描述:定时器工具类 *  * @author ruipeng.lrp * @since 2017/11/2 **/public class TimerService {    private static ScheduledExecutorService scheduledExecutor = Executors            .newSingleThreadScheduledExecutor(new ThreadFactory() {                public Thread newThread(Runnable r) {                    Thread t = new Thread(r);                    t.setName(TimerService.class.getName());                    t.setDaemon(true);                    return t;                }            });    public static ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay,            TimeUnit unit) {        return scheduledExecutor.scheduleWithFixedDelay(command, initialDelay, delay, unit);    }}
原创粉丝点击