Mule3.4.0 和Quartz StatefulJob整合
?
?
简单的job
import java.util.concurrent.CountDownLatch;import org.quartz.JobExecutionContext;import org.quartz.JobExecutionException;import org.quartz.StatefulJob;/** * <p>功能描述,该部分必须以中文句号结尾。<p> * * 创建日期 2013-8-17<br> * @author $Author$<br> * @version $Revision$ $Date$ * @since 3.0.0 */public class MyStatefulJob implements StatefulJob{ private CountDownLatch latch; public MyStatefulJob(CountDownLatch latch) { super(); this.latch = latch; } public void execute(JobExecutionContext context) throws JobExecutionException { System.out.println("打印次数:"+latch.getCount()); latch.countDown(); }}
?
quartz-custom-stateful-job-service.xml
<?xml version="1.0" encoding="UTF-8"?><mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns:test="http://www.mulesoft.org/schema/mule/test" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/current/mule-test.xsd http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd"> <!-- This latch is used in the test's code to determine if the custom job did its work --> <spring:bean id="latch" value="1" /> </spring:bean> <spring:bean id="job" /> </spring:bean> <model> <service name="quartzService"> <inbound> <quartz:inbound-endpoint jobName="eventTimer" repeatInterval="1000" repeatCount="1000000"> <quartz:custom-job job-ref="job" /> </quartz:inbound-endpoint> </inbound> </service> </model></mule>
?
?
测试方法:
import java.util.concurrent.CountDownLatch;import org.quartz.JobExecutionContext;import org.quartz.JobExecutionException;import org.quartz.StatefulJob;/** * <p>功能描述,该部分必须以中文句号结尾。<p> * * 创建日期 2013-8-17<br> * @author $Author$<br> * @version $Revision$ $Date$ * @since 3.0.0 */public class MyStatefulJob implements StatefulJob{ private CountDownLatch latch; public MyStatefulJob(CountDownLatch latch) { super(); this.latch = latch; } public void execute(JobExecutionContext context) throws JobExecutionException { System.out.println("打印次数:"+latch.getCount()); latch.countDown(); }}
?