spring定时器


java类代码:

import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
/**
* 定时器
* @author Administrator
*
*/
public class MapOutTime extends QuartzJobBean{
private TimesBiz biz;
public void setBiz(TimesBiz biz) {
this.biz = biz;

}
@Override
protected void executeInternal(JobExecutionContext arg0)
throws JobExecutionException {

biz.run();
System.out.println("搞定");//--------------->
}
}


applicationContext.Xml中的配置:

<!-- 定时器 -->

<bean id="MapOutTime"
class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass"
value="com.electricity.BIZ.MapOutTime">
</property>
<property name="jobDataAsMap">
<map>
<entry key="biz" value-ref="timesBiz"></entry>
</map>
</property>
</bean>

<!-- 定时器启动方式 -->

<bean id="electriTrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="MapOutTime"></property>
<property name="cronExpression">
<value>0 1,16,31,46 * * * ?</value>
<!--每天每时的1,16,31,46触发一次-->
</property>
</bean>

<!-- 启动定时器-->

<bean id="electriList"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="electriTrigger" />
</list>
</property>
</bean>

我用的spring.jar,有些低版本的Spring可能找不到.quartz.QuartzJobBean类,
另外加入一个quartz-all-1.6.0.jar包就OK



你可能感兴趣的:(quartz,定时器)