Reputation: 587
I'm trying out Quartz scheduler and managed to get it to work with Spring using Maven.
What I need to do is configure Quartz to store the jobs so that for a scheduled time it may execute the job. As far as I know there are two types of triggers in Quartz, Simple and Cron. And I also found out that there is something called JobStore in Quartz. I got it configured to some extent.
Could someone please give me a good reference/references on how to setup Quartz, JobStore? Big help, thank you.
Upvotes: 1
Views: 2163
Reputation: 422
You will usually create a Scheduler
from a factory class. Quartz can be setup in several ways.
By using the org.quartz.impl.StdSchedulerFactory.getDefaultScheduler()
. This will load the quartz.properties
file in the Quartz distribution if you have not provided your own.
By specifying your configuration as Key-Value pairs in a quartz.properties
file and loading it in org.quartz.impl.StdSchedulerFactory(java.lang.String fileName).getScheduler()
.
By specifying your configuration in a java.util.Properties
as Key-Value pairs and loading it in org.quartz.impl.StdSchedulerFactory(java.util.Properties props).getScheduler()
.
By using the spring-context-support
jar from the Spring Framework and using a higher level abstraction such as org.springframework.scheduling.quartz.SchedulerFactoryBean
.
etc.
Quartz will start triggering jobs only when the org.quartz.Scheduler#start()
has been invoked. Until this method is called the Scheduler
will be in Standby mode.
The Scheduler can be destroyed to release threads by calling org.quartz.Scheduler#shutdown()
.
@org.springframework.context.annotation.Configuration
public class QuartzExample {
...
@org.springframework.context.annotation.Bean
public org.springframework.scheduling.quartz.SchedulerFactoryBean schedulerFactory() {
org.springframework.scheduling.quartz.SchedulerFactoryBean factoryBean = new org.springframework.scheduling.quartz.SchedulerFactoryBean();
return factoryBean;
}
}
The bean definition above is enough to perform the following configuration:-
org.springframework.scheduling.quartz.AdaptableJobFactory
, which supports java.lang.Runnable
objects as well as standard Quartz org.quartz.Job
instances.org.quartz.simpl.SimpleThreadPool
with a pool size of 10. This is configured through the corresponding Quartz properties.org.quartz.impl.StdSchedulerFactory
, reading in the standard quartz.properties
from quartz.jar
.org.quartz.simpl.RAMJobStore
which does not support persistence and is not clustered.org.springframework.scheduling.quartz.SchedulerFactoryBean
implements org.springframework.context.SmartLifecycle
and org.springframework.beans.factory.DisposableBean
which means the life-cycle of the scheduler is managed by the Spring container. The org.quartz.Scheduler#start()
is called in the start()
implementation of SmartLifecycle
after initialization and the org.quartz.Scheduler#shutdown()
is called in the destroy()
implementation of DisposableBean
at application teardown.
You can override the startup behaviour by setting org.springframework.scheduling.quartz.SchedulerFactoryBean().setAutoStartup(false)
. With this setting you have to manually start the scheduler.All these default settings can be overridden by the calling the various setter methods on org.springframework.scheduling.quartz.SchedulerFactoryBean
.
I have provided a full working example on Github. If you are interested in an example that saves the jobs in a database checkout the HSQLDB branch of the same repository.
Upvotes: 0
Reputation: 13481
Just to give you another option, have you try task scheduling of Spring?. Nowadays I change all my old Quartz jobs for this and is easier to configure and you can use the annotations.
http://spring.io/blog/2010/01/05/task-scheduling-simplifications-in-spring-3-0/
Upvotes: 0
Reputation: 3225
You can have a look at these links Quartz JobStore with Spring Framework http://trimplement.com/using-spring-and-quartz-with-jobstore-properties/
If you still cant figure it out then let me know
Upvotes: 1