Announcement Announcement Module
Collapse
No announcement yet.
[Quartz] JobDetails on a CronTrigger Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Quartz] JobDetails on a CronTrigger

    Hello everyone
    it's 4 hours I'm trying to configure a quartz scheduler, I would like to register more jobDetail on a single CronTrigger.. is it possible?
    I already know Quartz, I worked with it some months ago and didn't had any problem to solve this task, so I watched the registerJobsAndTriggers method into the org.springframework.scheduling.quartz package and found this:

    Code:
    			if (this.triggers != null) {
    				for (Iterator it = this.triggers.iterator(); it.hasNext();) {
    					Trigger trigger = (Trigger) it.next();
    					if (this.scheduler.getTrigger(trigger.getName(), trigger.getGroup()) == null) {
    						// Check if the Trigger is aware of an associated JobDetail.
    						if (trigger instanceof JobDetailAwareTrigger) {
    							JobDetail jobDetail = ((JobDetailAwareTrigger) trigger).getJobDetail();
    							// Automatically register the JobDetail too.
    							if (!this.jobDetails.contains(jobDetail) && addJobToScheduler(jobDetail)) {
    								this.jobDetails.add(jobDetail);
    							}
    						}
    						this.scheduler.scheduleJob(trigger);
    					}
    					else if (this.overwriteExistingJobs) {
    						this.scheduler.rescheduleJob(trigger.getName(), trigger.getGroup(), trigger);
    					}
    				}
    			}
    and understood it's not possible to register more jobDetails on a trigger (JobDetail jobDetail = ((JobDetailAwareTrigger) trigger).getJobDetail()..
    Am I right?

    Thank you
    Fred

  • #2
    I thought in Quartz the relationship was the other way round. A job can have multiple triggers, but a trigger can only have one job.

    The documentation talks about the former, but I can't really see a discussion of the latter.
    http://www.opensymphony.com/quartz/w...alLesson2.html

    Comment


    • #3
      Karldmoore, thank you for the answer.
      I thought it was possible to use the group of the jobs to call them with one trigger but after I've tried to implement it I understood that you were right.
      Fred

      Comment


      • #4
        I as said I thought this was the case, but I wasn't sure. It's not really that clear.....

        Why Jobs AND Triggers? Many job schedulers do not have separate notions of jobs and triggers. Some define a 'job' as simply an execution time (or schedule) along with some small job identifier. Others are much like the union of Quartz's job and trigger objects.
        Kind hints at it. But then the code looks like you might be able to do it.....

        Code:
        JobbDetail jobDetail = new JobDetail("myJob", sched.DEFAULT_GROUP, DumbJob.class);
        Trigger trigger = TriggerUtils.makeDailyTrigger(8, 30);
        trigger.setStartTime(new Date());
        trigger.setName("myTrigger");
        sched.scheduleJob(jobDetail, trigger);
        http://www.opensymphony.com/quartz/w...alLesson2.html

        Comment


        • #5
          I tried with differents solutions but didn't find any way to do it.
          With the code you quoted you just scheduled one job, if you schedule another one you will loose the first.

          A possible solution is to implement a method which call differents other jobs:

          Code:
          public class Dispatcher {
          
            public void dispatch() {
              job1.execute();
              job2.execute();
            }
          
          }
          the trigger will call the dispatch() method which will call the other jobs.
          Thanks
          Fred

          Comment


          • #6
            Yeah, I thought that might be the case. I guess as you say, you could just packages everything up and run two tasks from the same job!

            Comment

            Working...
            X