
win.hupubao.common.scheduler.Scheduler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hupubao-common Show documentation
Show all versions of hupubao-common Show documentation
简单封装公共工具,二维码工具,驼峰转换工具,des加解密工具,http访问工具,字符串工具,日期工具
package win.hupubao.common.scheduler;
import java.util.concurrent.*;
/**
*
* @author wei.feihong
* @date 2018-03-24 13:04:13
* 任务调度器
*/
public class Scheduler {
private static final ScheduledExecutorService SVC = Executors
.newSingleThreadScheduledExecutor();
public static ConcurrentMap> futures = new ConcurrentHashMap<>();
public static void runTimer(String schedualerName,
long delay,
long interval,
Runnable runnable) {
futures.put(schedualerName , SVC.scheduleAtFixedRate(runnable, delay, interval, TimeUnit.MILLISECONDS));
}
public static void runOnce(String schedualerName,
long delay,
Runnable runnable) {
futures.put(schedualerName , SVC.schedule(runnable, delay, TimeUnit.MILLISECONDS));
}
public static void cancel(String schedualerName) {
futures.get(schedualerName).cancel(true);
futures.remove(schedualerName);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy