Scheduled

This commit is contained in:
redkale
2023-12-22 14:15:00 +08:00
parent ec26e3c9f7
commit ce36250e60
2 changed files with 18 additions and 6 deletions

View File

@@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit;
public @interface Scheduled {
/**
* 名称, 也可以用于第三方实现的定时任务组件的key
* 名称, 用于第三方实现的定时任务组件的key
*
* @return 名称
*/
@@ -32,6 +32,7 @@ public @interface Scheduled {
* cron表达式, 特殊值: <br>
* yearly、annually、monthly、weekly、daily、midnight、hourly、minutely
* 1m、2m、3m、5m、10m、15m、30m、1h、2h、3h、6h
* ${env.scheduling.cron}: 读取系统配置项
*
* @return cron表达式
*/
@@ -51,6 +52,8 @@ public @interface Scheduled {
* 5*60: 乘法表达式值为30
* ${env.scheduling.fixedDelay}: 读取系统配置项
* #delays: 读取宿主对象的delays字段值作为值字段类型必须是int、long数值类型
*
* 值大于0且fixedRate小于0则使用 ScheduledThreadPoolExecutor.scheduleWithFixedDelay
*
* @return 延迟时间
*/
@@ -63,6 +66,8 @@ public @interface Scheduled {
* 5*60: 乘法表达式值为30
* ${env.scheduling.fixedRate}: 读取系统配置项
* #intervals: 读取宿主对象的intervals字段值作为值字段类型必须是int、long数值类型
*
* 值大于0则使用 ScheduledThreadPoolExecutor.scheduleAtFixedRate
*
* @return 周期时间
*/
@@ -75,7 +80,8 @@ public @interface Scheduled {
* 5*60: 乘法表达式值为30
* ${env.scheduling.initialDelay}: 读取系统配置项
* #inits: 读取宿主对象的inits字段值作为值字段类型必须是int、long数值类型
*
*
* 值大于0且fixedRate和fixedDelay小于0则使用 ScheduledThreadPoolExecutor.schedule
* @return 起始延迟时间
*/
String initialDelay() default "-1";

View File

@@ -61,9 +61,9 @@ public class ScheduleManagerService implements ScheduleManager, Service {
protected final Logger logger = Logger.getLogger(this.getClass().getSimpleName());
private final ConcurrentHashMap<WeakReference, List<ScheduledTask>> refTaskMap = new ConcurrentHashMap<>();
protected final ConcurrentHashMap<WeakReference, List<ScheduledTask>> refTaskMap = new ConcurrentHashMap<>();
private final ReentrantLock lock = new ReentrantLock();
protected final ReentrantLock lock = new ReentrantLock();
@Resource(required = false)
protected Application application;
@@ -73,7 +73,7 @@ public class ScheduleManagerService implements ScheduleManager, Service {
private ScheduledThreadPoolExecutor scheduler;
private boolean enabled = true;
protected boolean enabled = true;
protected AnyValue config;
@@ -202,7 +202,7 @@ public class ScheduleManagerService implements ScheduleManager, Service {
String name, String cron, String fixedDelay, String fixedRate,
String initialDelay, String zone, TimeUnit timeUnit) {
if ((cron.isEmpty() || "-".equals(cron)) && "-1".equals(fixedRate) && "-1".endsWith(fixedDelay)) {
return null; //时间都没配置
return createdOnlyNameTask(ref, method, taskCount, name, cron, fixedDelay, fixedRate, initialDelay, zone, timeUnit); //时间都没配置
}
taskCount.incrementAndGet();
ZoneId zoneId = Utility.isEmpty(zone) ? null : ZoneId.of(zone);
@@ -217,6 +217,12 @@ public class ScheduleManagerService implements ScheduleManager, Service {
}
}
protected ScheduledTask createdOnlyNameTask(WeakReference ref, Method method, AtomicInteger taskCount,
String name, String cron, String fixedDelay, String fixedRate,
String initialDelay, String zone, TimeUnit timeUnit) {
return null;
}
protected Runnable createRunnable(final WeakReference ref, Method method) {
try {
if (!Modifier.isPublic(method.getModifiers())) {