标签:
一、继承QuartzJobBean,重写executeInternal方法
<bean name="statQuartzJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.cn.zero.QuartzTask">
</property>
</bean>
<bean id="statTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="statQuartzJob"></property>
<property name="cronExpression" value="0 0/15 * * * ? *"/>
</bean>
二、不须要继承、实现不论什么对象
<bean id="statQuartzJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
// statQuartzJob为定义的bean(能够注解生成或者配置)
<property name="targetObject" ref="statQuartzJob" />
// 运行的方法
<property name="targetMethod" value="execute" />
<!-- 是否同意任务并发运行。
当值为false时,表示必须等到前一个线程处理完成后才再启一个新的线程 -->
<property name="concurrent" value="false" />
</bean>
(1)、<bean id="statQuartzJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="statQuartzJobDetail" />
<!-- 每天10点运行一次 -->
<property name="cronExpression" value="0 0 10 * * ?"/>
</bean>
<!--时间配置也能够-->
(2)、<bean name="statQuartzJobTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="statQuartzJobDetail"/>
<property name="startDelay" value="10000"/>
<property name="repeatInterval" value="600000"/>
</bean>
总:启动定时任务
<!--启动定时生成 数据 -->
<bean name="jsbfQuartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="autoStartup" value="true"/>
<property name="triggers">
<list>
<ref bean="statQuartzJobTrigger" />
</list>
</property>
</bean>
标签:
原文地址:http://www.cnblogs.com/mengfanrong/p/5073964.html