spring 动态schedule
来源:互联网 发布:匡恩网络最新消息 知乎 编辑:程序博客网 时间:2024/06/05 19:41
sping的@Scheduled只能是常量如:
@Scheduled(cron = "1 3 0 * * ? ")
若想动态改变其值需要继承SchedulingConfigurer,如下:
import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.scheduling.Trigger;import org.springframework.scheduling.TriggerContext;import org.springframework.scheduling.annotation.EnableScheduling;import org.springframework.scheduling.annotation.SchedulingConfigurer;import org.springframework.scheduling.config.ScheduledTaskRegistrar;import org.springframework.scheduling.support.CronTrigger;import org.springframework.stereotype.Component;import java.util.Date;@Component@EnableSchedulingpublic class XXXSchedule implements SchedulingConfigurer { private Logger logger = LoggerFactory.getLogger(IndexCloseSchedule.class); private String cronConfig() { String cronTabExpression = "0 50 3 * * ? "; if (timeOfCloseIndex != null) { cronTabExpression = "0 50 4 * * ? "; } return cronTabExpression; } @Override public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { taskRegistrar.addTriggerTask(new Runnable() { @Override public void run() { //do something } },new Trigger() { @Override public Date nextExecutionTime(TriggerContext triggerContext) { String cron = cronConfig(); logger.info(cron); CronTrigger trigger = new CronTrigger(cron); Date nextExec = trigger.nextExecutionTime(triggerContext); return nextExec; } }); }}
阅读全文
0 0
- spring 动态schedule
- spring schedule
- 解析spring schedule
- 解析spring schedule
- 解析spring schedule
- Spring在schedule介绍
- spring schedule定时任务
- spring定时任务@schedule
- spring schedule定时任务
- Spring @Schedule Annotation详解
- Spring 计划任务 Schedule
- shiro spring-schedule security
- spring boot之schedule
- quartz,spring-quartz,spring-task,spring-schedule
- 解析spring schedule 任务调度
- Spring Schedule 任务调度实现
- spring schedule的简单实现
- spring schedule中的cron表达式
- 支付宝网页支付在IOS下唤起客户端支付后不能returnurl
- 常用正则
- 表【数组+链表】
- http://www.blogjava.net/robbie/archive/2009/04/05/264003.html
- 记录之----访问破10万
- spring 动态schedule
- <merge /> can be used only with a valid ViewGroup root and attachToRoot=true
- C语言初步-第11讲:算术运算符与算术表达式(分离各位数)
- 小白算法练习 dp练习001-区间dp NYOJ 石子合并,整数划分 POJ Brackets
- 修改mysql服务器的编码格式
- iOS 图片风格转换(CoreML)
- 目前手机号码运营商正则判断功能
- Java中为什么使用静态代码块
- Linux命令整理