io.github.kits.timer.DelayTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of whimthen-kits Show documentation
Show all versions of whimthen-kits Show documentation
Easy to use java tool library.
The newest version!
package io.github.kits.timer;
import java.util.function.Consumer;
/**
* 延迟定时任务, delay为long,period为long:从现在起过delay毫秒以后,每隔period毫秒执行一次。
*
* @project: kits
* @created: with IDEA
* @author: nzlong
* @date: 2019/02/20 15:19 | February. Wednesday
*/
public class DelayTask {
private volatile static DelayTask delayTask = null;
public static DelayTask getDelayTask() {
if (delayTask == null) {
synchronized (DelayTask.class) {
if (delayTask == null) {
delayTask = new DelayTask();
}
}
}
return delayTask;
}
/**
* delay 为long类型:从现在起过delay毫秒执行一次
*
* @param taskName
* @param task
* @param delay
* @param
*/
public void addTask(String taskName, Consumer task, long delay) {
TimedKit.addTask(taskName, null, null, task, delay, null, null, null);
}
/**
* 从现在起过delay毫秒以后,每隔period毫秒执行一次。
*
* @param taskName
* @param task
* @param delay
* @param period
* @param
*/
public void addTask(String taskName, Consumer task, long delay, long period) {
TimedKit.addTask(taskName, null, null, task, delay, period, null, null);
}
/**
* 从现在起过delay毫秒以后,每隔period毫秒执行一次。
*
* @param taskName
* @param t
* @param task
* @param delay
* @param period
* @param
*/
public void addTask(String taskName, T t, Consumer task, long delay, long period) {
TimedKit.addTask(taskName, t, null, task, delay, period, null, null);
}
}