Quartz与Srping结合简单示例
2016-09-20 16:06
627 查看
Job类
Spring配置文件
测试结果:
源码下载
package net.xsbiz.common; public class MakeHtml { // 调用的方法 public void execute() throws InterruptedException{ // 需要做的事情 System.out.print(new Date()); } }
Spring配置文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- Timer schedule --> <!--要调度的对象--> <bean id="jobBean" class="net.xsbiz.common.MakeHtml" /> <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="jobBean" /> <!-- 执行"jobBean"中的execute方法 --> <property name="targetMethod" value="execute" /> <!--将并发设置为false--> <property name="concurrent" value="true" /> </bean> <bean id="trigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <!-- 定义 Job 何时执行 --> <property name="jobDetail" ref="jobDetail" /> <!--表达式,我的是每 30 执行一次--> <property name="cronExpression" value="0/1 * * * * ?" /><!-- “ 0 0 12 * * ? ”会在每天中午 12 点触发 执行;“ 0 15 10 ? * 6L ”会在每个月的最后一个星期五的早上 10:15 触发 Job 执行 --> </bean> <!-- 总管理类如果将lazy-init='false'那么容器启动就会执行调度程序 --> <bean id="startQuertz" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false" > <property name="autoStartup" value="true"></property> <property name="triggers"> <list> <!--作业调度器,list下可加入其他的调度器--> <ref bean="trigger" /> </list> </property> </bean> </beans>
测试结果:
参考资料:
QuartZ Cron表达式
源码下载
相关文章推荐
- 常用的JS与XML结合用法 简单示例
- xmlHTTP xmlDOC 与 C#中DataSet的结合 实现AJAX简单示例
- Spring定时器Quartz的简单示例
- Spring(3.2.3)+Quartz(2.2.1)的简单示例
- Java调度框架Quartz简单示例
- xmlHTTP xmlDOC 与 C#中DataSet的结合 实现AJAX简单示例
- Quartz之手动启动和关闭定时器简单示例
- jquery easyui 结合jsp简单展现table数据示例
- 使用Quartz2.1.6+Spring3.0实现任务调度简单示例
- quartz简单定时任务示例
- 简单示例:AJAX结合PHP代码实现登录
- xmlHTTP xmlDOC 与 C#中DataSet的结合 实现AJAX简单示例
- 简单示例AJAX结合PHP代码实现登录效果代码
- Quartz.Net 学习随手记之02 简单示例
- Db4o结合Linq、Lambda表达式的简单示例
- 常用的JS与XML结合用法 简单示例
- 简单示例AJAX结合PHP代码实现登录效果代码
- ExtJS与AjaxPro结合的简单示例
- jquery easyui 结合jsp简单展现table数据示例
- 使用Quartz2.1.6+Spring3.0实现任务调度简单示例