Dynamic job scheduling using Spring 3

I developed a web crawler that crawls with the launch URL as the seed parameter. I want to allow users to plan this task from the point of view of Job, if possible.

I am currently using Spring 3.1.2and Hibernate. I need to provide users with an interface that receives cronJob parameters and based on this I want to start a search robot. Is it possible to do this with spring.

I read a little about Quartz, but articles about SO or other websites are completely incomprehensible or incomplete in order to fully understand how to implement the scheduler in spring.

I know the basics that have three components

  • SchedulerFacotry
  • Trigger
  • Work (service to run)

Hope someone can lead me in the right direction.

+5
source share
1 answer

A quartz planner is the right tool for the job. For some reason, almost all tutorials are focused on defining tasks at startup, in XML - while Quartz is fully capable of (re) scheduling tasks at run time.

You can and should use Spring to run 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);

( Java ), ( , CRON) , . Spring. Spring .

+9

All Articles