之前介紹過可以在plsql軟件上編寫oracle的定時器以及配合存儲過程進行存儲數據。今天來講講怎麼在服務器上的xml配置定時器,實現定時執行代碼段的功能。
- xml配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
default-lazy-init="false">
<!-- 調用定時器 -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="SetTime" /><!-- 測試定時器 -->
</list>
</property>
</bean>
<!-- 定時器定時 -->
<bean id="SetTime" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="createTime"/>
</property>
<property name="cronExpression">
<value>0 31 10 ? * *</value><!--設置觸發定時器時間 -->
</property>
</bean>
<!-- 創建定時器 ,並且分配執行方法 -->
<bean id="createTime" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="timeToService"/>
</property>
<property name="targetMethod">
<value>testTime</value>
</property>
</bean>
<!-- 定時器指向的Service -->
<bean id="timeToService" class="ffcs.cn.peam.time.service.TimeService"/>
</beans>
2.service代碼
package ffcs.cn.peam.time.service;
public class TimeService {
public void testTime(){
System.out.println("定時器觸發了啊");
}
}
簡單的定時就完成了。