/**
* 动态定时任务
*/
public void rejob(){
class TaskJob implements SchedulingConfigurer{
private String cron="-";
public TaskJob(String cron){
this.cron=cron;
}
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
scheduledTaskRegistrar.addTriggerTask(new Runnable() {
@Override
public void run() {
// 任务逻辑
}
},new Trigger(){
@Override
public Date nextExecutionTime(TriggerContext triggerContext) {
CronTrigger cronTrigger = new CronTrigger(cron);
Date date = cronTrigger.nextExecutionTime(triggerContext);
return date;
}
});
}
}
}
2020-12-05
最新推荐文章于 2023-08-21 10:08:06 发布