在spring3 中的新引入的task 命名空间。可以部分取代 quartz 功能,配置和API更加简单,并且支持注解方式。但是如果需要使用比较复杂的任务调度。还是建议使用quartz。
第一步:
在Spring的相关配置文件中(applicationContext.xml或者是{project_name}_servelt.xml或者是独立的配置文件如XXX_quartz.xml)中配置并开启Spring Schedule Task.注意其中高亮的部分是必须的。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
">
<mvc:annotation-driven />
<context:component-scan base-package="com.mytools.validator.engine" />
<!-- 启动定时器 -->
<task:annotation-driven/>
</beans>
第二步:
可以在类中的需要定时执行的方法下指定如下Annotation
@Scheduled(cron="0 33/3 * * * ?") //每小时的33分钟开始执行,每3分钟执行1次
public void start() throws ServletException {
validate();
}
备注:其实@Scheduled中可以指定如下3中时间表达式:
(1)fixedRate:每隔多少毫秒执行一次该方法。如:
@Scheduled(fixedRate=2000) // 每隔2秒执行一次
public void scheduleMethod(){
System.out.println("Hello world...");
}
(2)fixedDelay:当一次方法执行完毕之后,延迟多少毫秒再执行该方法。
(3)cron:详细配置了该方法在什么时候执行。cron值是一个cron表达式。如:
@Scheduled(cron="0 0 0 * * SAT")
public voidarchiveOldSpittles() {
// ...
}
到指定时间后,任务总是执行2次的解决方案:
这是因为我们很容易在一个基于Spring的Web工程中启动2个定时线程:
第一次:web容器启动的时候,读取applicationContext.xml(或者别的Spring核心配置文件)文件时,会加载一次。
第二次:Spring本身会加载applicationContext.xml(或者别的Spring核心配置文件)一次。
解决方案:将你的Task的相关配置独立出来并在web.xml中通过context-param加载。而不是通过spring加载。
1) 独立出Spring-Task,如新命名一个文件名叫cms_quartz.xml
2) 在web.xml中去加载该文件:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/cms-servlet.xml,classpath:cms-quartz.xml</param-value>
</context-param>
相关推荐
springboot动态配置定时任务(schedule),可不重启项目实现开关重启任务,改变任务定时规则
shedule
主要介绍了spring定时任务(scheduler)的串行、并行执行实现解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
在交互式观察模式下启动测试运行器。 有关更多信息,请参阅有关的部分。 yarn build 将用于生产的应用程序构建到build文件夹。 它在生产模式下正确地捆绑了 React 并优化了构建以获得最佳性能。 构建被缩小,...
此扩展程序允许从UC Davis Schedule Builder导出到Google日历。 该扩展程序将“导出”按钮插入到Schedule Builder网页中。完成时间表后,点击导出按钮会将时间表导入Google日历。请阅读...
基于websocket api和MQTT服务的HomeAssistant灌溉系统在不同的mqtt主题中以json格式创建灌溉计划。 当您单击网页中的发布时,它会通过websocket api... shedule2 max : 255 shedule3 : name : shedule3 max : 255 shedu
grsu-shedule-解析器 使用超级简单 该模块旨在解析 GRSU 计划页面。 数据- 是一个带有时间表的 html 页面,解析数据- 准备好的每周时间表。 var SheduleParse = require ( 'grsu-shedule-parser' ) ; SheduleParse...
计划GitHub动作的实践(如何使用cron触发动作) 示例回购,以了解“ on.schedule”工作流程在GitHub Actions中如何工作。 以下安排好的工作流程在添加了评论。 请参阅的评论中的实际工作流程。
matlab说话代码时间表 用于水生植物生长系统的光继电器,由俄勒冈州波特兰市的每日日出和日落时间控制。 我们使用MATLAB代码从网站上读取每天的日出和日落时间(特别是对于波特兰或OR数据:)。...
Yandex Alice的技能“创建时间表”
该项目旨在简化学校的管理工作。
关键时间旋转器 从带有期限限制请求的键数组中获取有效的键 用法 var Keytimerotator = require ( 'keytimerotator' ) ; var schedule = "0 * * * * *" ;... //after shedule get key from begin keys 安装 npm install
2、shedule条件 22 3、threadprivate指令 24 六、分段并行 25 七、嵌套并行 29 八、OpenMP中的常用函数 33 1、设置线程数目 33 2、获取线程数目 33 3、获取最多线程数目 33 4、返回线程ID 33 5、获取程序可用的...
包含一个shedule.asm,test1.asm,test1.com
请参阅 sample-config.ini启动手动执行: $ php -f /PATH_TO/phpssh.php /PATH_TO/sample-config.ini >> file_to_log.logOR$ sh copiador.bat /path-to-config/sample-config.ini或在 crontab 中 shedule:...
shedule仕様書 見積もり仕様書 週報仕様書 リスト管理仕様書 单体测试仕様書 结合测试仕様書 打合せ議事録仕様書 プロジェクト体制図 発注仕様書 質問管理シート 品質基準書 レビュー報告書 チェックリスト プロジェ...
代码如下: Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/–>使用open方式打开的窗体 //使用地址方式 window.opener.location.href=’m_Shedule_Main.aspx’;...
简单的 mysql 转储和 ftp 上传。 单击一次即可完成所有操作。 软件是用java swing构建的,也支持shedule任务
固化条件(Cure CondiTIan)(常温、加温、紫外光、红外光、微波) 固化速度和时间(Cure Shedule) 外观(Appearance)(透明、半透明、颜色) 填充料(Filler) 所粘接的材料(Adherent Material) 粘度...
3. 在 Fixture Wizard (灯具向导) 界面下点击 From Library (从灯库选择) 。 4. 在弹出的对话框中找到 Manufacturer Filter 中输入 Arkaos,找到 arkaos@mediamaster@layer_full_1.0.xmlp,点击 OK。 5. 在 ...