标签:
1、实现和循环调度类似
public class QuartzJob3{ public void test(){ SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss"); System.out.println("Spring新型方法-使用定时触发器-被调用"+sdf.format(new Date())); } }
<!-- 注入调度类对象 --> <bean id="quartzJob2" class="action.QuartzJob2"/> <bean id="quartzJob3" class="action.QuartzJob3"/>
<!-- 配置任务调度管理类对象--> <bean id="methodInvoking1" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="quartzJob2"/> <property name="targetMethod" value="test"/> </bean> <bean id="methodInvoking2" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="quartzJob3"/> <property name="targetMethod" value="test"/> </bean>
<!-- 定义触发器-简单触发器 --> <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean"> <property name="jobDetail" ref="methodInvoking1"/> <property name="startDelay" value="1000"/> <property name="repeatInterval" value="2000"/> </bean> <!-- 定义触发器-定时触发器 --> <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="methodInvoking2"/> <property name="cronExpression" value="0 15 * * * ?"/> </bean>
<!-- 启动任务 -->
<bean id="quartzFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="simpleTrigger"/>
<ref local="cronTrigger"/>
</list>
</property>
</bean>
<!-- 启动任务 -->
<bean id="quartzFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="simpleTrigger"/>
<ref local="cronTrigger"/>
</list>
</property>
</bean>
标签:
原文地址:http://www.cnblogs.com/6da6da/p/4693331.html