Clustered @schedule annotations in Spring
My codebase is currently using a quartz.properties
crontab file to define a series of jobs in our Spring web application. Our quartz configuration now looks like this:
org.quartz.scheduler.instanceId=AUTO
org.quartz.scheduler.jmx.export=true
org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount=20
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.misfireThreshold=6000000
org.quartz.jobStore.isClustered=true
org.quartz.jobStore.dataSource=dataSourceConnectionProvider
I recently fell in love with Spring annotation @scheduled
and would like to take advantage of it. There are many examples where we have some sort of bean job that essentially wraps a single service method - the annotations seem like they would remove a lot of templates and our code would be more legible as a result.
However, I cannot figure out how I can get the same guarantees from Spring Scheduling that we are doing with vanilla quartz right now. That is, setting up isClustered=true
and implementing a job store to use the backup database allows us to guarantee that our jobs will run once per cluster without doing something nasty like declaring a master node and checking hostnames, which is not even a good guarantee. for us, since we have a variable number of nodes. However, it seems like it should be possible. Spring planning is obviously very well aware of quartz and I have to imagine that there is a way to implement TaskScheduler
that will provide these guarantees.
source to share
No one has answered this question yet
Check out similar questions: