修改:删除多余依赖调整,代码风格调整
This commit is contained in:
@@ -1,23 +1,19 @@
|
||||
package net.tccn.timer;
|
||||
|
||||
import net.tccn.timer.scheduled.ScheduledCycle;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Timers {
|
||||
|
||||
private static TimerExecutor timerExecutor = new TimerExecutor(1);
|
||||
private static final TimerExecutor timerExecutor = new TimerExecutor(1);
|
||||
|
||||
/**
|
||||
* 本地延时重试
|
||||
*
|
||||
* @param supplier
|
||||
* @param millis
|
||||
* @param maxCount
|
||||
*/
|
||||
public static void tryDelay(Supplier<Boolean> supplier, long millis, int maxCount) {
|
||||
timerExecutor.add(TimerTask.by("try-delay-task-" + Utility.uuid(), ScheduledCycle.of(0), task -> {
|
||||
timerExecutor.add(TimerTask.by("try-delay-task-" + UUID.randomUUID().toString().replaceAll("-", ""), ScheduledCycle.of(0), task -> {
|
||||
if (supplier.get() || task.getExecCount() == maxCount) {
|
||||
task.setComplete(true);
|
||||
}
|
||||
@@ -32,12 +28,9 @@ public class Timers {
|
||||
|
||||
/**
|
||||
* 本地延时:延时时间极短的场景下使用 (如:1分钟内)
|
||||
*
|
||||
* @param runnable
|
||||
* @param millis
|
||||
*/
|
||||
public static void delay(Runnable runnable, long millis) {
|
||||
timerExecutor.add(TimerTask.by("delay-task-" + Utility.uuid(), ScheduledCycle.of(millis), task -> {
|
||||
timerExecutor.add(TimerTask.by("delay-task-" + UUID.randomUUID().toString().replaceAll("-", ""), ScheduledCycle.of(millis), task -> {
|
||||
runnable.run();
|
||||
task.setComplete(true);
|
||||
}));
|
||||
|
Reference in New Issue
Block a user