Java – makes the quartz scheduler persistent without JDBC
•
Java
We are building an application about mongodb and need to run cron like jobs regularly When the project is based on RDBMS with JDBC, I have used quartz before
Since we have used mongodb as our master data store in this project, I don't want to introduce RDBMS just to retain quartz jobs, but it seems that there is no type of jobstore to implement mongodb
Can anyone recommend using mongodb to support quartz, or a simple alternative to quartz? My requirements are quite simple (run various Java jobs in some configuration, long lacron)
Solution
We use spring to run quartz, which is just an XML file with job definition and cron expression
Announce a job in spring:
<bean name="myJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailfactorybean"> <property name="concurrent" value="false"/> <property name="targetBeanName" value="myBean"/> <property name="targetmethod" value="myScheduledMethod"/> </bean> <bean id="myJobTrigger" class="org.springframework.scheduling.quartz.crontriggerBean"> <property name="jobDetail" ref="myJob"/> <!-- every 30s --> <property name="cronExpression" value="0/30 * * * * ?"/> </bean>
Quartz wiring:
<bean id="schedulerfactorybean" class="org.springframework.scheduling.quartz.Schedulerfactorybean"> <property name="triggers"> <!-- List of batch jobs to be fed to the scheduler. --> <list> <ref bean="myTrigger"/> </list> </property> </bean>
Run it:
import org.springframework.context.support.ClassPathXmlApplicationContext; public class App { public static void main( String[] args ) throws Exception { new ClassPathXmlApplicationContext("jobs-context.xml"); } }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码