首页 > 代码库 > Spring定时器配置的两种方法

Spring定时器配置的两种方法

1.

<bean id="locationTimerTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail">
<bean id="locationTimerJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="http://www.mamicode.com/com.location.util.LocationTimeTask" /><!-- 配置定时器的类 -->
<property name="group" value="http://www.mamicode.com/TEST" />
<property name="durability" value="http://www.mamicode.com/true" />
</bean>
</property>
<property name="cronExpression">
<value>*/10 * * * * ?</value> <!-- 每10s触发一次 */10 * * * * ? * 50 9 * * ? 0 18 17 * * ?-->
</property>
</bean>

 

2.

<!--业务类的配置-->
<bean id="myJobA" class="com.location.service.LocationTaskServiceImpl"></bean>

<!-- JobDetail的配置-->
<bean id="myJobDetailA" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="myJobA"></property>
<property name="targetMethod" value="http://www.mamicode.com/registerCallInfterface"></property>
<property name="concurrent" value="http://www.mamicode.com/false"/>
<!--是否允许任务并发执行。当值为false时,表示必须等到前一个线程处理完毕后才再启一个新的线程-->
</bean>

<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail">
<ref bean="myJobDetailA"/>
</property>
<property name="startDelay">
<value>10000</value>   <!-- 延时10000ms -->
</property>
<property name="repeatInterval">
<value>50000000</value>  <!-- 每隔50000000执行一次 -->
</property>
</bean>

Spring定时器配置的两种方法