定时器

来源:互联网 发布:聚宝盆直播软件安卓版 编辑:程序博客网 时间:2024/05/23 11:45
xml配置
        <!-- 定时器配置 --><bean id="quartzJob" class="com.service.impl.QuartzServiceImpl"><property name="configFilePath"><value>${configFilePath}</value></property></bean><!-- 定义调用对象和调用对象的方法 --><bean id="jobtask"class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"><!-- 调用的类 --><property name="targetObject"><ref bean="quartzJob" /></property><!-- 调用类中的方法 --><property name="targetMethod"><value>refreshData</value></property></bean><!-- 定义触发时间 --><bean id="doTime" class="org.springframework.scheduling.quartz.CronTriggerBean"><property name="jobDetail"><ref bean="jobtask" /></property><!-- cron表达式 --><property name="cronExpression"><value>${quartz.time}</value></property></bean><!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 --><bean id="startQuertz" lazy-init="false" autowire="no"class="org.springframework.scheduling.quartz.SchedulerFactoryBean"><property name="triggers"><list><ref bean="doTime" /></list></property></bean>


properties  xml配置 : quartz.time=0 0/1 * * * ?


java代码

public interface QuartzService {      public void refreshData();}public class QuartzServiceImpl implements QuartzService {      public void refreshData() {        //实现代码      }}


0 0
原创粉丝点击