mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add ProxySelector
This commit is contained in:
@@ -105,17 +105,6 @@ public class CronUtil {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加入定时任务
|
||||
*
|
||||
* @param schedulingPattern 定时任务执行时间的crontab表达式
|
||||
* @param task 任务
|
||||
* @return 定时任务ID
|
||||
*/
|
||||
public static String schedule(final String schedulingPattern, final Runnable task) {
|
||||
return scheduler.schedule(schedulingPattern, task);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量加入配置文件中的定时任务
|
||||
*
|
||||
|
@@ -238,17 +238,6 @@ public class Scheduler implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增Task,使用随机UUID
|
||||
*
|
||||
* @param pattern {@link CronPattern}对应的String表达式
|
||||
* @param task {@link Runnable}
|
||||
* @return ID
|
||||
*/
|
||||
public String schedule(final String pattern, final Runnable task) {
|
||||
return schedule(pattern, new RunnableTask(task));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增Task,使用随机UUID
|
||||
*
|
||||
|
@@ -26,12 +26,12 @@ public class AddAndRemoveMainTest {
|
||||
CronUtil.setMatchSecond(true);
|
||||
CronUtil.start(false);
|
||||
CronUtil.getScheduler().clear();
|
||||
final String id = CronUtil.schedule("*/2 * * * * *", (Runnable) () -> Console.log("task running : 2s"));
|
||||
final String id = CronUtil.schedule("*/2 * * * * *", () -> Console.log("task running : 2s"));
|
||||
ThreadUtil.sleep(3000);
|
||||
CronUtil.remove(id);
|
||||
Console.log("Task Removed");
|
||||
|
||||
CronUtil.schedule("*/3 * * * * *", (Runnable) () -> Console.log("New task add running : 3s"));
|
||||
CronUtil.schedule("*/3 * * * * *", () -> Console.log("New task add running : 3s"));
|
||||
Console.log("New Task added.");
|
||||
}
|
||||
}
|
||||
|
@@ -86,7 +86,8 @@ public class CronTest {
|
||||
@Test
|
||||
@Disabled
|
||||
public void addAndRemoveTest() {
|
||||
final String id = CronUtil.schedule("*/2 * * * * *", (Runnable) () -> Console.log("task running : 2s"));
|
||||
final String id = CronUtil.schedule("*/2 * * * * *",
|
||||
() -> Console.log("task running : 2s"));
|
||||
|
||||
Console.log(id);
|
||||
CronUtil.remove(id);
|
||||
|
@@ -0,0 +1,16 @@
|
||||
package org.dromara.hutool.cron.demo;
|
||||
|
||||
import org.dromara.hutool.core.lang.Console;
|
||||
import org.dromara.hutool.cron.CronUtil;
|
||||
|
||||
public class SimpleDemo {
|
||||
public static void main(String[] args) {
|
||||
// 打开秒匹配
|
||||
CronUtil.setMatchSecond(true);
|
||||
// 添加任务
|
||||
CronUtil.schedule("*/2 * * * * *",
|
||||
() -> Console.log("Hutool task running!"));
|
||||
// 启动
|
||||
CronUtil.start();
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* 定时任务示例
|
||||
*
|
||||
*/
|
||||
package org.dromara.hutool.cron.demo;
|
Reference in New Issue
Block a user