change cron

This commit is contained in:
Looly
2020-10-31 20:57:22 +08:00
parent 6674dcbde7
commit 905a4da3ee
12 changed files with 216 additions and 49 deletions

View File

@@ -22,6 +22,9 @@ public class CronTest {
// 支持秒级别定时任务
CronUtil.setMatchSecond(true);
CronUtil.start();
ThreadUtil.waitForDie();
Console.log("Exit.");
}
@Test
@@ -32,27 +35,27 @@ public class CronTest {
CronUtil.getScheduler().setDaemon(false);
CronUtil.start();
ThreadUtil.sleep(3000);
ThreadUtil.waitForDie();
CronUtil.stop();
}
@Test
@Ignore
public void cronTest2() {
public void cronWithListenerTest() {
CronUtil.getScheduler().addListener(new TaskListener() {
@Override
public void onStart(TaskExecutor executor) {
Console.log("Listen task start!");
Console.log("Found task:[{}] start!", executor.getCronTask().getId());
}
@Override
public void onSucceeded(TaskExecutor executor) {
Console.log("Found task:[{}] success!", executor.getCronTask().getId());
}
@Override
public void onFailed(TaskExecutor executor, Throwable exception) {
Console.error("Found task:[{}] failed!", executor.getCronTask().getId());
}
});
@@ -65,7 +68,7 @@ public class CronTest {
}
@Test
// @Ignore
@Ignore
public void addAndRemoveTest() {
String id = CronUtil.schedule("*/2 * * * * *", (Runnable) () -> Console.log("task running : 2s"));