kettle结合quartz框架实现任务调度

Quartz定机制
首先导入jar包程序内 quartz-all-1.6.0.jar

创建XML
TimeConfig.xml 名字自定义

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"">
<beans>
<bean id="mainTask" class="net.timed.MainTask"/> //要执行任务类
//jar类
<bean id="mainJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="mainTask"/>//类添加定器
</property>
<property name="targetMethod">
<value>execute</value> //定执行类面哪
</property>
</bean>

<bean id="timeTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="mainJob"/>
</property>
<!--
0 0 10,14,16 * * ? 每午10点午2点4点
0 0/30 9-17 * * ? 朝九晚五工作间内每半
0 0 12 ? * WED 表示每星期三午12点
"0 0 12 * * ?" 每午12点触发
"0 15 10 ? * *" 每午10:15触发
"0 15 10 * * ?" 每午10:15触发
"0 15 10 * * ? *" 每午10:15触发
"0 15 10 * * ? 2005" 2005每午10:15触发
"0 * 14 * * ?" 每午2点午2:59期间每1钟触发
"0 0/5 14 * * ?" 每午2点午2:55期间每5钟触发
"0 0/5 14,18 * * ?" 每午2点2:55期间午6点6:55期间每5钟触发
"0 0-5 14 * * ?" 每午2点午2:05期间每1钟触发
"0 10,44 14 ? 3 WED" 每三月星期三午2:102:44触发
"0 15 10 ? * MON-FRI" 周至周五午10:15触发
"0 15 10 15 * ?" 每月15午10:15触发
"0 15 10 L * ?" 每月午10:15触发
"0 15 10 ? * 6L" 每月星期五午10:15触发
"0 15 10 ? * 6L 2002-2005" 2002至2005每月星期五午10:15触发
"0 15 10 ? * 6#3" 每月第三星期五午10:15触发

面quartz语 定单位
-->
<property name="cronExpression">
<value>0 0/5 * * * ?</value> //定语
</property>
</bean>
<bean id="sfb" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="timeTrigger"/>
</list>
</property>
</bean>
</beans>

//面类我XML引入类
package net.timed;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MainTask {
public void execute() throws IOException
{
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("do my job"+dateFormat.format(new Date()));
Runtime.getRuntime().exec("cmd /c start E:/mbl/BusinessOffice/MoneDB/bin/bakup.bat");
}
}

web.xmlTimeConfig.xml添加进作监听
系统启候自监听事件

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns=""
xmlns:xsi=""
xsi:schemaLocation="
/web-app_2_5.xsd">
<context-param>
<param-name>
contextConfigLocation
</param-name>
<param-value>
/WEB-INF/TimerConfig.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

quartz spring定机制

猜你喜欢

转载自blog.csdn.net/maenlai0086/article/details/90635336