How can I custom number of job per second (job/s) that be executed by quartz scheduler? - spring-boot

I'm attempting to practice with Quartz Scheduler in a small Spring Boot Application. I really want to know if any way to determined number of job per second (job/s) that be executed by quartz scheduler. I checked all quart properties in documentation but can not find anything.
Thanks all!

You can maanage this from your property file though property name is depend on which Job store are you using,
For JDBC Job store, property name is org.quartz.threadPool.threadCount.
Check out http://www.quartz-scheduler.org/documentation/quartz-2.1.7/configuration/ official documentation for respective implementation.
[documentation is for 2.1.7]

Related

Spring boot Quartz to skip some jobs

I use spring boot + maven multi module project. I am using cluster-aware Quartz configuration, so job details are stored in the database. Lets say, 2 Spring boot maven modules (projects) are using quartz, but I want each module run it is own jobs, which are different to each module. In that case, when I start one module, it actually tries to run jobs from other module too because Quartz engine is reading the jobs to run from the database. So how do I specify in each module to run only specific jobs related to at module?
One way is to have different table prefixes for each module. Is there any other way to use the same quartz tables between 2 different modules, but each module decide which jobs to run?
I have almost the same. My solution was:
Job A writes a flag into the DB table next to the job "running_by" jobA and when its done, it remove the flag.
So JobB checks if this Job has a flag already. If not it will proceed, if yes it skip this job because JobA is already running it.
config a property in quartz.properties
org.quartz.jobStore.isClustered = true
that can make quartz work in cluster mode

Spring task:scheduled or #Scheduler to restrict a Job to run in multiple instance

I have one #Scheduler job which runs on multiple servers in a clustered environment. However I want to restrict the job to run in only in one server and other servers should not run the same job once any other server has started it .
I have explored Spring Batch has lock mechanism using some Database table , but looking for any a solution only in spring task:scheduler.
I had the same problem and the solution what I implemented was a the Lock mechanism with Hazelcast and to made it easy to use I also added a proper annotation and a bit of spring AOP for that. So with this trick I was able to enforce a single schedule over the cluster done with a single annotation.
Spring Batch has this nice functionality that it would not run the job with same job arguments twice.
You can use this feature so that when a spring batch job kicks start in another server it does not run.
Usually people pass a timestamp as argument so it will by pass this logic, which you can change it.

When spring-boot app multi-node deploy, how to handle cron job?

When I use spring task handle a simple sync job! But when I deploy multi-node, how I make sure the cron job just run one time.
Maybe you say that:
1. Use distributed-lock control a flag before the crob job run.
2. Integrated quartz cluster function.
But I hope spring task #EnableScheduling can add a flag argument, so as we can set a flag when launch app.
We are using https://github.com/lukas-krecan/ShedLock with success, zookeeper provider in particular.
Spring boot, in a nutshell, doesn't allow any type of coordination between multiple instances
of the same microservice.
All the work of such a coordination is done by the third parties that spring boot gets integrated with.
One example of this is indeed a #Scheduled annotation.
Another is DB migration support via flyway.
When many nodes start and the migration has to be done, flyway is responsible to lock the migration table by itself, spring boot has nothing to do with it.
So, bottom line, there is no such support and all options that you've raised can work.

What modules to use for a synchronization service in Java/Spring?

I'm willing to build a synchronization service in Java. The use case is, that i'm fetching data from an exchange-service (via Exchange Web Services), normalize the data a bit (process probably) and then write it to a backend via GraphQL. I already had a look around the spring modules, but am not quite sure what modules to use. I found spring batch and spring quartz.
The synchronization will have to trigger all X seconds, fetch information from the Exchange, look what's in the backend already and update what's needed.
Do you guys have any suggestions? I started implementing this whole thing in nodejs before, but as it has to run on both, Windows Servers and Docker/Linux, it has been a real pain to keep it running smooth (mostly because bundling nodejs to an application for Windows is pain).
Difference between Spring Batch & Quartz:
Spring Batch and Quartz have different goals. Spring Batch provides functionality for processing large volumes of data and Quartz provides functionality for scheduling tasks.
So Quartz could complement Spring Batch, A common combination would be to use Quartz as a trigger for a Spring Batch job using a Cron expression.
Conclusion : So basically Spring Batch defines what should be done, Quartz defines when it should be done.
Quartz is a scheduling framework. Like "execute something every hour or every last friday of the month"
Spring Batch is a framework that defines that "something" that will be executed.
You can define a job, that consists of steps. Usually a step is something that consists of item reader, optional item processor and item writer, but you can define a custom stem. You can also tell Spring batch to commit on every 10 items and a lot of other stuff.
You can use Quartz to start Spring Batch jobs.
Recommended for your use case :
Quartz scheduling as you want trigger after specific interval.
Reference :https://projects.spring.io/spring-batch/faq.html

Spring Boot & Batch Schedule

I have been checking all over to find out how to configure a schedule for Spring Batch. I am using Spring boot with a web ui. The user can go and select a time to run a job and this must be persistence to a database and run when the time comes. A different user can schedule the same job for a different time. Does spring batch have anything similar to this? If not then what is the best way to go about this? need some examples.
There are no out of the box solution which just work. You can do this with minimal coding. Try to persist the schedule in database and on start up your application you can read all the schedule and schedule using batch scheduler. Also you can do the same thing when user enter new schedule with out restart.
Cron based scheduler is already available in spring. Just need to persist and schedule from your side.
scheduler.schedule(task, new CronTrigger("* 15 9-17 * * MON-FRI"));
documentation on scheduler is given here

Resources