James Raitsev
James Raitsev

Reputation: 96391

Quartz scheduler, knowing when job completes

I have a situation that relies on knowing when the job completes.

Basically a singleton manager keeps track of a bunch of job and their schedules. Assuming B follows A, when A executes scheduler deleted B's job and reschedules it to be closer in time to A.

The problem I ran into is notifying the manager when job finished

public class Action extends ScheduledEvent implements Job {

    public Action() {
    }

    protected Action(String name, MomentInTime momentInTime, FireEventFrequency repeatFrequency) throws SchedulerException {
        super(momentInTime, repeatFrequency);
    }

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // Do some work
        EventScheduleManager.getInstance().eventComplete(this);

    }
}

I realize why that happens is due to the reflection and that at time of scheduling this is reinitialized and is now known by the manager.

Is there a way around it? How would you notify a manager entity that job it scheduled has completed?

Upvotes: 3

Views: 2873

Answers (3)

James Raitsev
James Raitsev

Reputation: 96391

I ended up passing the job name back to the manager

   EventScheduleManager.getInstance().eventComplete
        (jobExecutionContext.getJobDetail().getName());

And the manager itself maintained the Map<String,ScheduledEvent> took it from there

Upvotes: 2

mindas
mindas

Reputation: 26713

You could create a wrapper, something like this:

public class DoubleAction extends ScheduledEvent implements Job {
    private final Job job1,job2;

    public DoubleAction(Job job1, Job job2) {
       this.job1=job1;
       this.job2=job2;
    }

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
       job1.execute(jobExecutionContext);
       job2.execute(jobExecutionContext);
    }
}

Upvotes: 1

Michael Brown
Michael Brown

Reputation: 9153

As I understand, their recommendation for a workflow-based job (where you have to guarantee one follows the other) is to have the first job create an entry for its successor for immediate execution when it's done.

Upvotes: -1

Related Questions