第一种: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);
}
}
}
}

spring 定时任务 scheduled Cron表达式

cron 定时任两种配置方式的更多相关文章

  1. Oozie与Coordinator调度讲解及系统时区配置与定时触发两种配置方式

    1:修改本地linux时区 查看时区 - 号代表西  + 号 代表东 北京时间是东八区 设置时区的配置文件所在位置 cd /usr/share/zoneinfo/ 选择以亚洲的上海 的时区为基址 删除 ...

  2. hibernate 一对一 one to one的两种配置方式

    hibernate中one-to-one两种配置方式 标签: hibernateHibernateone-to-one 2013-02-19 17:44 11445人阅读 评论(1) 收藏 举报  分 ...

  3. Hibernate中双向多对多的两种配置方式

    Hibernate中双向多对多的两种配置方式 1.建立多对多双向关联关系 package cn.happy.entitys; import java.util.HashSet; import java ...

  4. IOC容器在web容器中初始化——(一)两种配置方式

    参考文章http://blog.csdn.net/liuganggao/article/details/44083817,http://blog.csdn.net/u013185616/article ...

  5. 第四节:框架前期准备篇之进程外Session的两种配置方式

    一. 基本介绍 1. 背景:Asp.Net默认的Session机制是进程内,存储在服务器端内存中,有这么几个缺点: ①:既然存在内存中,空间有限,不能存储大数据量信息,数据量多的话Session会被挤 ...

  6. springboot之jackson的两种配置方式

    springboot 针对jackson是自动化配置的,如果需要修改,有两种方式: 方式一:通过application.yml 配置属性说明:## spring.jackson.date-format ...

  7. 学习JavaWeb aop两种配置方式

    aop aop:面向切面编程,它可以解决重复代码. aop有两种方式: 一..xml方式 1.在springmvc-servlet.xml中配置aop,应用bean文件: <!--aop配置-- ...

  8. (一)spring aop的两种配置方式。

    sring aop的方式有两种:(1)xml文件配置方式(2)注解的方式实现,我们可以先通过一个demo认识spring aop的实现,然后再对其进行详细的解释. 一.基于注解的springAop配置 ...

  9. eureka集群的两种配置方式:配置文件方式与DNS方式

    eureka client获取serviceUrls(eureka server地址)列表的过程: 1. 根据use-dns-for-fetching-service-urls属性判断是从dns还是从 ...

随机推荐

  1. exsi中使用vSphere客户端复制克隆虚拟机

    免费的VMWare ESXi5.5非常强大,使用ESXi经常会遇到这样的问题,我需要建立多个虚拟机,系统一个一个安装很麻烦.VMware ESXi.VMware vCenter Server 和 vS ...

  2. CodeForces.1174D.ArraySplitting.(后缀和数组 + 贪心)

    题目链接 参考代码: #include <cstdio> #include <algorithm> using namespace std; typedef long long ...

  3. enWin使用部分中文字库

    在小型嵌入式设备中有时需要简单的人机2交互界面,小型GUI有很多,比较常用的有STenWin,UCGUI,enwin,Embedded Wizard GUI.对与STenWin和enWin区别主要在S ...

  4. EasyUi 表格自适应宽度

    第一次接触EasyUi想要实现表格宽度自适应,网上找了好多文章,都没有实现,有网友实现了可是自己看不懂.可能是太简单高手都懒得分享,现在把自己的理解和实现记录一下,希望可以帮到向自己一样的菜鸟,步骤如 ...

  5. Linux延时执行命令at

    也许你的Ubuntu没有at命令,先安装 - sudo apt install at 在某时刻执行命令 - at 15:30:回车之后,需要在at后输入指令,表示在15:30要执行的指令 - 比如输入 ...

  6. JavaScript、ES6中的类的继承

    类的继承 extends  connstructor  super 例1: class Father { constructor(){} money(){ console.log("1000 ...

  7. [好好学习]在VMware中安装Oracle Enterprise Linux (v5.7) - (1/5)

    在想到Oracle Enterprise Linux,第一时间就是在Oracle官网上找到资源,但是,出现以下图片

  8. 三、Windows下用FFmpeg+nginx+rtmp搭建直播环境 实现推流、拉流

    一.环境 1.开发环境:windows 2.开发工具:FFmpeg.nginx.nginx-rmtp-module (链接:https://pan.baidu.com/s/119d2GeMzddas_ ...

  9. python基础——对时间进行加减

    在datetime模块中有一个timedelta这个方法,它代表两个datetime之间的时间差.. In [42]: datetime.datetime.now().strftime('%Y-%m- ...

  10. PTA 错题记录

    程设期中考, 记录一下曾经做错的选择填空. 1. 2. 3. 4. 5. 6.