I have developed a web crawler which crawls with Start URL as seed parameter. I want to allow users to schedule this task in terms of a Job if possible.
Currently I am using Spring 3.1.2
and Hibernate
. I need to give users a front end which receives cronJob Parameters and based on that I want to run the crawler. Is it possible to do it using spring.
I read a bit about Quartz
but the articles on SO or other websites are not at all clear or they are not complete in order to fully understand how to implement a scheduler in spring.
I know basics that there are three components to it
I hope someone could guide me in correct direction.
Quartz scheduler is just the right tool for the job. For some reason almost all tutorials focus on defining jobs at startup, in XML - while Quartz is fully capable of (re-|un-) scheduling jobs at runtime.
You can and should takr advantage of Spring to start the Quartz Scheduler, but then you can interact with it directly from your code. Here is a simple example from the documentation:
JobDetail job = newJob(SimpleJob.class)
.withIdentity("job1", "group1")
.build();
CronTrigger trigger = newTrigger()
.withIdentity("trigger1", "group1")
.withSchedule(cronSchedule("0/20 * * * * ?"))
.build();
scheduler.scheduleJob(job, trigger);
Here you define a job (piece of Java code to run), trigger (when to run it, user can supply any valid CRON expression) and wrap it all by scheduling it. The scheduler instance can be injected by Spring. Spring will also handle proper shutdown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With