cron 定时任两种配置方式
第一种:xml文件方式
<bean id="commonTimer" class="com.course.wx.timer.CommonTimer"></bean><!--定时任务Bean -->
<bean name="startQuartz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="releaseQuestionTrigger" />
<ref bean="dealHistoryQuestionTrigger" />
</list>
</property>
</bean> <bean id="dealHistoryQuestionTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail">
<ref bean="dealHistoryQuestion" />
</property>
<property name="cronExpression">
<value>0 23 15 * * ?</value>
</property>
</bean> <bean id="dealHistoryQuestion"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="commonTimer" />
</property>
<property name="targetMethod">
<value>dealHistoryQuestion</value>
</property>
</bean>
第二种:注解方式
xml配置
<!-- Spring定时器注解开关-->
<task:annotation-driven />
<!-- 此处对于定时时间的配置会被注解中的时间配置覆盖,因此,以注解配置为准 -->
<task:scheduled-tasks scheduler="myScheduler">
<task:scheduled ref="scheduledTaskManager" method="autoCardCalculate" cron="* */5 * * * *"/>
</task:scheduled-tasks>
<task:scheduler id="myScheduler" pool-size="10"/>
Java代码
@Component("scheduledTaskManager")
@Lazy(value=false)
public class ScheduledTaskManager {
public static final Integer RECOVER = 3;
/**
* cron表达式:* * * * * *(共6位,使用空格隔开,具体如下)
* cron表达式:*(秒0-59) *(分钟0-59) *(小时0-23) *(日期1-31) *(月份1-12或是JAN-DEC) *(星期1-7或是SUN-SAT)
*/
@Autowired
ProcedureService procedureService;
/**
* 定时卡点计算。每天凌晨 02:00 执行一次
* @throws AdqException
*/
@Scheduled(cron = "* */5 * * * *")
public void autoCardCalculate() throws AdqException {
List<WorkOrder> suspendItems = procedureService.querySuspendItems();
if (suspendItems != null && suspendItems.size() > 0) {
for (WorkOrder order : suspendItems) {
order.setStateId(RECOVER);
order.setNotes("恢复执行");
procedureService.updateState(order);
}
}
}
}
cron 定时任两种配置方式的更多相关文章
- Oozie与Coordinator调度讲解及系统时区配置与定时触发两种配置方式
1:修改本地linux时区 查看时区 - 号代表西 + 号 代表东 北京时间是东八区 设置时区的配置文件所在位置 cd /usr/share/zoneinfo/ 选择以亚洲的上海 的时区为基址 删除 ...
- hibernate 一对一 one to one的两种配置方式
hibernate中one-to-one两种配置方式 标签: hibernateHibernateone-to-one 2013-02-19 17:44 11445人阅读 评论(1) 收藏 举报 分 ...
- Hibernate中双向多对多的两种配置方式
Hibernate中双向多对多的两种配置方式 1.建立多对多双向关联关系 package cn.happy.entitys; import java.util.HashSet; import java ...
- IOC容器在web容器中初始化——(一)两种配置方式
参考文章http://blog.csdn.net/liuganggao/article/details/44083817,http://blog.csdn.net/u013185616/article ...
- 第四节:框架前期准备篇之进程外Session的两种配置方式
一. 基本介绍 1. 背景:Asp.Net默认的Session机制是进程内,存储在服务器端内存中,有这么几个缺点: ①:既然存在内存中,空间有限,不能存储大数据量信息,数据量多的话Session会被挤 ...
- springboot之jackson的两种配置方式
springboot 针对jackson是自动化配置的,如果需要修改,有两种方式: 方式一:通过application.yml 配置属性说明:## spring.jackson.date-format ...
- 学习JavaWeb aop两种配置方式
aop aop:面向切面编程,它可以解决重复代码. aop有两种方式: 一..xml方式 1.在springmvc-servlet.xml中配置aop,应用bean文件: <!--aop配置-- ...
- (一)spring aop的两种配置方式。
sring aop的方式有两种:(1)xml文件配置方式(2)注解的方式实现,我们可以先通过一个demo认识spring aop的实现,然后再对其进行详细的解释. 一.基于注解的springAop配置 ...
- eureka集群的两种配置方式:配置文件方式与DNS方式
eureka client获取serviceUrls(eureka server地址)列表的过程: 1. 根据use-dns-for-fetching-service-urls属性判断是从dns还是从 ...
随机推荐
- 【mysql】select子句顺序
sleect…from (1)where (2)group by (3)having (4)order by (5)limit
- 《jmeter:菜鸟入门到进阶系列》
jmeter是我从事软件测试工作以来接触的第一个性能测试工具,也是耗费时间精力最多的一个工具,当然,学习jmeter过程中,由于知识储备不够,也顺带学习了很多其他相关的一些知识. 一直有个想法,就是把 ...
- 创建客户端项目并读取服务化的配置中心(Consul + Spring Cloud Config)
创建客户端项目并读取服务化的配置中心 将配置中心注册到服务中心(Consul) POM文件添加依赖: <dependency> <groupId>org.springframe ...
- PTA第二题
#include<string.h> #include<stdio.h> #include<malloc.h> ]; ][]={"ling",& ...
- Appium+Python之异常自动截图
运行过程中出现异常情况,我们怎么直观的看到呢?最简单的方法就是可以把异常现象截图下来. 思路:我这里采用get_screenshot_as_file(filename)方法,filename通过获取时 ...
- 20191115PHP cookie登入实例
首先是登入页面 <form action="" method="post"> <input type="text" nam ...
- centos7.4安装mysql
yum -y install mysql mysql-server mysql-devel mysql-server报错:No package mysql-server available,另外两个没 ...
- tomcat启动报错:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
windows系统: 部署了一个Tomcat8.5.15,bin目录下startup.bat执行,结果提示Neither the JAVA_HOME nor the JRE_HOME enviro ...
- uboot中Kconfig架构的理解
1./u-boot-2019.07/Kconfig 是顶层Kconfig mainmenu "U-Boot $UBOOTVERSION Configuration" #这是总me ...
- CSS3 Transform实例
移动translate <!doctype html> <html> <head> <meta charset="utf-8"> & ...