Spring Scheduler Disallow Concurrent Alternative - java

When scheduling a task in Quartz, you have the ability to set misfires and rescheduling. This could be used in the example scenario whereby there is a job that runs every 30 mins, and potentially there could be a backlog and and the job would execute for longer than 30 mins. To prevent the same job running twice you could use the #DisallowConcurrentExecution. Once complete the job would then execute the second instance that is queued by using simpleSchedule().withMisfireHandlingInstructionNowWithExistingCount().
Now in Spring Scheduler there doesn't appear to be this fine grained ability, with just the fixed-rate and fixed-delay options to schedule it every 30 mins or wait 30 mins after the previous job completed. Without using the hammer route of restricting to a single thread, as I want to increase the thread count for other batch jobs to run concurrently, what would be the best method of recreating the Quartz behaviour?

So it looks like with the basic Spring Scheduler there isn't such a mechanism. To do this either use the Spring Quartz Scheduler, or Quartz directly.

Related

How to queue misfired jobs in Quartz?

Is there a way to queue thousands of misfired jobs in quartz scheduler?
I want to avoid having all misfired jobs to fire all at once.
We're using quartz 2.2.1.
Just limit the amount of concurrently executable jobs.
For example set the property org.quartz.threadPool.threadCount to 10 will cause that only 10 jobs could be executed in parallel. I.e. other jobs will be queued (depending on your MisfireInstructions).

Google App Engine's 1 minute cron limitation

I am using GAE Java for my web application and I need to run a scheduled task every 30 seconds. However, I know that the minimum is 1 minute. Any ideas (and possibly working example ) of how to do that? I've read that you can use Task Queues instead, but couldn't find how to schedule queue tasks.
You can "schedule tasks" by specifying when they should run. They have a parameter that tells it the delay to wait so you create 2 task queues one runs "now" (delay 0) and the other runs with 30sec delay. See the countdown property.https://developers.google.com/appengine/docs/python/taskqueue/tasks#countdown_arg
You can then have the 1minute cron do that.
However, the frontend will never sleep plus you will consume more with the task queues. You can also use a single backend and have it run 2 threads or your own scheduler in a loop. Keep a cron to restart the backend if it goes down (which will after about 15min)

Asynchronous job scheduling in Quartz

Do java Quartz Scheduler support Asynchronous job scheduling.If so,is it by default or have to customize jobs to run asynchronously.
Not only it supports this behaviour but there is basically no other way. Once you schedule a job and a trigger (in any thread) this job will be executed asynchronously in a thread pool. You have some control over that thread pool like the number of threads.
Another issue is parallel execution of the same job. By default the same job can run in multiple threads started by different threads, unless the job is stateful.
Yes and it should be by default. I am using Quartz in my Grails application for my website and it spins off new threads for each job.

Scheduling a job to begin after a Job fired by CronTrigger completes using Quartz

I was wondering if it was possible to schedule a job to start after a job fired by a CronTrigger successfully completes, using Quartz in Java?
From the feature Documentation:
As Jobs are completed, they return a
JobCompletionCode which informs the
scheduler of success or failure. The
JobCompletionCode can also instruct
the scheduler of any actions it should
take based on the success/fail code -
such as immediate re-execution of the
Job.
I think the JobChainingJobListener should be interesting:
Keeps a collection of mappings of which Job to trigger after the completion of a given job.
This is assuming you use the CronJob from quartz of course.
Otherwise you'd need to program (in java) some kind of socket listener, and wrap the cron job in a script which, at the end, triggers Java by writing something on the socket (or pipe, or web service call, whatever you like). Your java code would then trigger the quartz job.

How to schedule multiple jobs in quartz scheduler using same trigger?

I am using quartz scheduler in my spring project. I have to run a job after another job which is scheduled to run in every 15 mins? I cant run this job concurrently as both of this jobs have to access same mail account using different protocols(one to send:smtp and other to receive: imap) and it may cause problems. Please reply quickly, as its an urgent requirement.
Just write a wrapper job class that launches second job after the first. You could then reuse separate jobs in the future if there will be any necessity.
You could do something with writing a job listener to recognize when the first job ends, and have it start the second. But the solution first suggested by mindas is easier - wrap both your jobs in another Job implementation, which is the one you actually schedule.

Categories

Resources