スプリングベースのタスクスケジュール
1、springのJDK Timerスケジュールへのサポート springにおける構成:
springにおける構成:
javaコード:
<bean id="helloworlTask" class="com.ufinity.dragoon.quartz.HelloworldTask"></bean>
<bean id="task" class="org.springframework.scheduling.timer.MethodInvokingTimerTaskFactoryBean">
<property name="targetObject">
<ref bean="helloworlTask"/>
</property>
<property name="targetMethod">
<value>hello</value>
</property>
<property name="arguments">
<value> </value>
</property>
</bean>
<bean id="timerTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
<property name="delay" value="1000"></property>
<property name="period" value="3000"></property>
<property name="timerTask" ref="task"></property>
</bean>
<bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">
<property name="scheduledTimerTasks">
<list>
<ref bean="timerTask"/>
</list>
</property>
</bean>
javaコード:public class HelloworldTask{
public void hello(String name){
System.out.println("hello,"+name);
}
}
2、スプリング対Quartzのスケジュールサポートspringにおける構成:
<!-- spring quartz -->
<bean id="printJob" class="com.ufinity.dragoon.quartz.PrinterJob"></bean>
<bean id="jobtask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="printJob"/>
</property>
<property name="targetMethod">
<value>print</value>
</property>
</bean>
<bean id="doPrint" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="jobtask"/>
</property>
<property name="cronExpression">
<value>0/40 * * * * ? </value>
</property>
</bean>
<bean id="quartzManager" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="doPrint"/>
</list>
</property>
</bean>
javaコード:
public class PrinterJob {
private int count = 0;
public void print(){
System.out.println("invoking successfully! "+count+" ");
System.out.println("**********************************");
count++;
}
}