I developed a web application and one of the function is to send emails.
I like to have the behaviour whereby the actual sending of emails is done in a batch job. Meaning when user click on the trigger button in online screen. The job for sending emails will be scheduled to run instead of immediately run.
How to do that exaclty? Any sample code references etc?
I would recommend Quartz website where I learnt Quartz.
For Spring integration, follow http://static.springsource.org/spring/docs/1.2.9/reference/scheduling.html
This tutorial will give you better idea how to schedule a job in quartz.
In example DumbJob.class will implement Job interface from Quartz and in turn provide execute() method. This method will contain batch job code.
I think what you really want to do is implement a queue / worker model here. The job gets added to a queue and periodically, workers poll the queue to determine if anything needs to be done.
Related
I need to schedule multiple tasks in the spring boot java project and to do task settings by bringing the value of the task execution time from a database and updating the scheduled appointment during runtime in my program.
Clarification of use case, I have a Rest API, It requires me to make a new schedule making a POST request on the endpoint
the request includes in the body of the necessary information about this schedule, such as the time of the task and the job to be performed, and after making the request, the task is scheduled in my program and executed at its appointed time
I looked at some technology that provides solutions to make his schedules like spring schedule and Quartz, But I cannot create a custom schedule and add it to the scheduling queue in the system, according to the case I mentioned
What technologies should I use for it?
You have the answer in your question. Just creat a scheduler and call the same methods that your api calls internally. example
I'm creating a web application, based on struts.. The thing is, that i need to do some scheduled task, or better than that an event listener...
The idea is that my web app saves some date fields in a database, and i want to make something that checks the content of every rows, and execute a method for the fields which date is the current date.
My problem is that i have never performed a listener or a scheduled task before, and I'm very confused i don't know how to do it.. I've been reading other articles, but i don't get how to integrate it with my webapp..
Thanks in advance !
Quartz Scheduler is the best one in scheduling a job. Please refer the following links
http://www.javabeat.net/quartz-scheduler-tutorial/
http://www.mkyong.com/struts2/struts-2-quartz-scheduler-integration-example/
(a) Needing a scheduled task is entirely different than needing an event listener. Focus your question.
(b) For a scheduled task…
The older class bundled with Java is a Timer.
The newer way is a ScheduledExecutorService.
Each has pros and cons. Search StackOverflow for examples.
we have requirement like to start, stop and resume individual job and get the status for individual job to display on web page. Please help me on the same to implement this functionality in Quartz Scheduler.
You should obtain a reference to the quartz Scheduler object, and you can do all from there. In spring you can obtain it through org.springframework.scheduling.quartz.SchedulerFactoryBean
Check this question for a better spring-quartz support.
I am developing a front end to trigger a quartz job on the fly.
I have a form in the JSF page whose click action will dynamically trigger a quartz job.
The job is invoked by the following statement, the job is triggered and everything works fine.
scheduler.triggerJob("Job1",Scheduler.DEFAULT_GROUP,jobDataMap);
From what I understand the job seems to run in a separate thread and the execution of the calling function does not wait for the job to be over.
Since I am invoking the job from front end, I would like to wait till the job is over before I navigate to a different JSF page. So I can display an error message if the job fails.
I would also like to display a message to the user, "Processing job, please wait.." until the job is actually over.
Any ideas on how to accomplish this will be appreciated.
Thanks !
You can register a Trigger/Job Listener to be notified when a Quartz job has completed.
How you would get that asynchronous update back to the user in JSF, I'm not so sure. I would expect a good solution to depend on your application architecture, the version of JSF, and maybe even the library support you have available. It does sound like the kind of thing you'd expose as a pollable service and use an AJAX-updated component to me, though.
I am considering using the Quartz framework to schedule the run of several hundred jobs.
According to their API, jobs can be scheduled to run at certain moments in time but not to run one after the other (and stop a chain of jobs if one fails).
The only recommended methods I was able to find are:
Using a listener which notices the completion of a job and schedule the next trigger to fire (how to coordinate this?)
Each job will receive a parameter containing the next job to run and, after completing the actual work, schedule its run. (Cooperative)
Do you know a better method to create a workflow of jobs in Quartz?
Can you recommend other methods/framework for implementing a workflow in Java ?
EDITED: In the meantime I found out about OSWorkflow which appears to be a good match for what I need. It appears that what I need to implement is a "Sequence Pattern".
When Quartz documentation talks about "Job", it is referring to a class implementing the "Job" Interface, which is really just any class with an "execute" method that takes in the Quartz Context object. When creating this implementation you can really do whatever you want.
You could create an implementation of the Quartz Job Interface which simply calls all the jobs in your workflow in series, and throws a JobExecutionException exception on failure.
It sounds to me like you want Quartz to schedule the first job, and chain everything off that.
Have you looked at encapsulating each task using the Command Pattern, and linking them together ?
I've worked on a project called Dynamic Task Scheduler that use Quartz to execute job chains implementing a simple workflow in a fault-tolerant way (definied in XML format).
Take a look at http://sourceforge.net/projects/dynatasksched/
The project is beta, but I think it can gives you some ideas to start..
Hope it's useful!
For job chaining support for Quartz, you may want to check the QuartzDesk project that I have been involved in. In version 2.0. we have added a powerful job chaining engine that enables you to orchestrate your Quartz jobs without the need to modify your application code.
The engine takes care of propagating the job execution result and other parameters from the source job to the chained target job.
QuartzDesk comes with a GUI that allows you to dynamically update your job chains without disrupting your application.