Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Quartz with Spring

In my application there is a requirement to be able to create Scheduled Job(s) depending on the type of Request that comes in (Dynamically).

Can I still use Spring to create and trigger Jobs? If Yes, how?

Any help would be useful.

like image 778
a-sak Avatar asked Feb 18 '09 20:02

a-sak


People also ask

What is Quartz in spring?

Quartz is an open source Java library for scheduling Jobs. It has a very rich set of features including but not limited to persistent Jobs, transactions, and clustering. You can schedule Jobs to be executed at a certain time of day, or periodically at a certain interval, and much more.

Does Spring Batch use Quartz?

You can use Quartz to start Spring Batch jobs. So basically Spring Batch defines what should be done, Quartz defines when it should be done.

What is Quartz misfire?

A misfire occurs if a persistent trigger “misses” its firing time because of the scheduler being shutdown, or because there are no available threads in Quartz's thread pool for executing the job. The different trigger types have different misfire instructions available to them.


1 Answers

Given that the SchedulerFactoryBean exposes a native Quartz Scheduler object, you can wire that directly into your controller class, and then dynamically create and register triggers and jobs with the Scheduler object.

Spring itself can't be used for the scheduling of the dynamically created jobs, since Spring's bean support will be used for statically configured jobs, but the native Quartz Scheduler API is reasonable enough to use on its own (barely). As fr triggering of the jobs, that Quartz's job, not Spring's.

edit: either I'm mis-understanding the original question, or everyone else is. The other answers all detail how to statically wire up a series of quartz jobs using Spring, but the question was how to dynamically schedule jobs as requests come in.

like image 117
skaffman Avatar answered Oct 05 '22 23:10

skaffman