I have nested task to schedule:
(1). A daily master task downloading scheduling information, which is a List of job names with timestamps
(2). schedule the job in the scheduling information I just downloaded according to its timestamp
I am not sure how the nested jobs work in Quartz. It seems that I need a CronTrigger triggering a job, which contains multiple SimpleTriggered jobs. Are there any way to do that? Are there any alternatives?
Thanks.
Lily
They aren't really nested jobs.
You are correct in that the master job needs a CronTrigger. But when that job runs it will cycle through the list of jobs downloaded creating a job and a SimpleTrigger for each entry. You can get a Scheduler from the CronJob's JobExecutionContext and add the jobs to it.
And bingo, all your jobs are scheduled.
You basically need to run Quartz inside of your Quartz job. This doesn't really make sense, why don't your just run all of the jobs with Quartz configurations? I don't think this nesting is a good idea.
Related
I have a specific scenario in which I need to run a scheduler at 00:00 AM every day for different timezones. Currently, I am using spring scheduler in fixed rate of 10 minutes so that I will not miss any timezones(Not an ideal solution though!).
But what I need is, I want this scheduler to be running at the specfic time instead of running every 10 minutes. To explain it in detail
Assume I have 3 time zones: T1, T2 and T3.
I want the scheduler to be triggered only 3 times a day. 00:00 AM of T1, T2 and T3 respectively.
I dont want to write 3 schedulers for this because the business logic is the same.
Does springs scheduler provides that flexibility of running a scheduler at different timezones?
If it doesn't are there any library out there which does this job for us?
You can try using quartz to create triggers based on crons. Spring has a native support for quartz with spring-boot-starter-quartz dependency. I would start with this https://www.baeldung.com/spring-quartz-schedule and https://howtodoinjava.com/spring-batch/batch-quartz-java-config-example for spring batch incase you are interested in batch
Quartz supports multiple triggers too for a single job.
I'm using Spring XD to execute a batch task, which itself is divided into two separate jobs living in the same (job:)module.
Now I'm quite new to Spring XD/Batch so I only have a rather basic understanding of the framework. I'd like to know if there's a way to address each of those jobs separately? I know I can deploy a job giving it the modules name, however I haven't found a way to specify which job I want to deploy.
Should there be only one job per module? And if not, how can I talk to/deploy each of those jobs separately?
Please let me know if the description of the problem is unclear.
Thanks
Spring XD requires one "main" job to be executed within the module. That being said, Spring XD does support Spring Batch's concept of nested jobs where one job is used to orchestrate the launching of multiple jobs which sounds like it would fit your bill. The "main" job is required to have the id "job". After that, that job can call any number of other jobs packaged in the same module via job steps.
I am writing a hadoop job that should collect the start and finish times of all jobs that ran in a cluster, and upload this data to a blob. However, I'm not sure how to get this information, as a job doesn't seem to have access to the job tracker. Any ideas?
You could make use of getLaunchTime() and getFinishTime() methods provided by the Class JobInProgress. The API also has a JobTracker Class that provides getJobsFromQueue(String queue) method that can be used to get all the jobs submitted to the particular Queue.
Apart from these methods these classes also have some other very useful methods which you might find helpful.
HTH
I need a mechanism for implementing asynchronous job scheduling in Java and was looking at the Quartz Scheduler, but it seems that it does not offer the necessary functionality.
More specifically, my application, which runs across different nodes, has a web-based UI, via which users schedule several different jobs. When a job is completed (sometime in the future), it should report back to the UI, so that the user is informed of its status. Until then, the user should have the option of editing or cancelling a scheduled job.
An implementation approach would be to have a Scheduler thread running constantly in the background in one of the nodes and collecting JobDetail definitions for job execution.
In any case, there are two the questions (applicable for either a single-node or multi-node scenario):
Does Quartz allow a modification or a cancellation of an already scheduled job?
How can a "callback" mechanism be implemented so that a job execution result is reported back to the UI?
Any code examples, or pointers, are greatly appreciated.
Does Quartz allow a modification or a cancellation of an already scheduled job?
You can "unschedule" a job:
scheduler.unscheduleJob(triggerKey("trigger1", "group1"));
Or delete a job:
scheduler.deleteJob(jobKey("job1", "group1"));
As described in the docs:
http://quartz-scheduler.org/documentation/quartz-2.x/cookbook/UnscheduleJob
Note, the main difference between the two is unscheduleing a job removes the given trigger, while deleting the job removes all triggers to the given job.
How can a "callback" mechanism be implemented so that a job execution result is reported back to the UI?
Typically, in the web world, you will poll the web server for changes. Depending upon your web framework, there may be a component available (Push, Pull, Poll?) that makes this easy. Also, what you will need to do is store some state about your job on the server. Once the job finishes you may update a value in the database or possibly in memory. This, in turn, would be picked up by the polling and displayed to the user.
To complete the answer of #johncarl with Quarz also have this
handle event's before and after the excution implementing SchedulerListener interface
Groups your jobs
Support with Enterprise Edition
Most important the cron expressions here's the documentation
I have an application that needs to play some specifics audios(mp3) periodically. Let me give one example: Every Monday at 8:00am -> hello.mp3.
How can I do that in Java??
I´m trying using Calendar, JodaTime, but I cant do it.
Depends, if you are using Java EE, you can use EJB Timer. And there is always Quartz http://www.quartz-scheduler.org/
What you want is a scheduled task. Timer class can provide this for you. Here is an example to get you started example
What a Timer can help you to achieve is so minimum, Quartz Scheduler is a well-known (and easy-to-use) scheduler that accepts cron-like expression.
If you use Spring in your application, it has a scheduling module that can keep your Quartz code even cleaner.
You should use java.util.Timer to define schedules and java.util.TimerTask to define job. You can also use well-known Quartz Scheduler.
If you use Spring, you can use its scheduling service (it can be configured to use either Quartz Scheduler or java.util.Timer in its work).
If you run desktop App, the easiest way is to use java.util.Timer. For more complicated schedules use Quartz Scheduler.