2
votes

I want to use camel->quartz component to schedule some job to be done at specified time interval.

But I want that in synchronized manner. Means, Next execution of scheduled job should only start after completion of current execution.

I created Route and Scheduler Service for Servicemix.

QuartzRoute.java

public class QuartzRoute extends RouteBuilder {
@Override
public void configure() throws Exception {

    from("quartz://myGroup/myTimerName?cron=0/1+*+*+*+*+?").process(new SchedulerService());
}

}

SchedulerService.java

public class SchedulerService implements Processor {

public void process(Exchange exchange) throws Exception {

    System.out.println("I'm running every 5 sec...");
    Thread.sleep(5000);     
    System.out.println("Exiting iteration ");
}

}

Here, I want "I'm running every 5 sec..." and "Exiting iteration " to be printed in same order every time. In sort i want this SchedulerService to be executed again only after completion of current execution.

1

1 Answers

4
votes

Use the stateful=true option of the quartz component. See Scheduled with fixed delay in quartz scheduler?

"stateful jobs are not allowed to execute concurrently, which means new triggers that occur before the completion of the execute(xx) method will be delayed."