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还是从 ...
随机推荐
- 关于java的数组
一定要写成 int[] arr = new int[30] 这样每个元素默认为0; 介样子的 如果写成 int[] arr = {1,2,3,4}; 那么他的长度就是4
- 在react中用装饰器来装饰connect
假设我们在react中有如下header组件: import React, { PureComponent } from 'react'; import { connect } from 'react ...
- 什么是 Python 自省?
Python 自省是 Python 具有的一种能力,使程序员面向对象的语言所写的程序在运行时,能够获得对象的类 Python 型.Python 是一种解释型语言,为程序员提供了极大的灵活性和控制力.
- SQL SERVER 数据库跨服务器备份
原文:https://www.cnblogs.com/jaday/p/6088200.html 需求介绍:每天备份线上正式库并且把备份文件复制到测试服务器,测试服务器自动把数据库备份文件还原. 方案介 ...
- Html5移动端页面自适应布局详解(rem布局)
在移动设备上进行网页的重构或开发,首先得搞明白的就是移动设备上的viewport,通读网上的各种对于viewport的解释之后 大概viewport可以理解为三种 1.layout viewport ...
- 命令行运行python -m http.server报错
最近在学习网站搭建,借助python搭建服务器时,在网站目录启动python服务时报错,如下: UnicodeDecodeError: 'utf-8' codec can't decode byte ...
- IE9的兼容性
/* 解决IE9表格错位 */ .el-table--border th:last-of-type.gutter { display: table-cell !important; width: 50 ...
- 遍历并读取指定目录下的所有文件内容,写入Map集合然后输出在控制台和本地文件
public class FileWrite { public static void main(String[] args) throws Exception { //封装数据源目录 File sr ...
- 一、Vs2019扩展多了 导航到反编译的源码中运行
一.导航到反编译的源码中运行
- 使用GDB调试时attach ID不被允许
在进入gdb后,直接使用attach ID,出现下面的情况: Could not attach to process. If your uid matches the uid of the targ ...