4

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.

рüффп
  • 5,172
  • 34
  • 67
  • 113
Dhaval Patel
  • 141
  • 1
  • 9

1 Answers1

5

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."

Community
  • 1
  • 1
soilworker
  • 1,317
  • 1
  • 15
  • 32
  • Hi, thanks for the comment. Can i define _stateful_ property in case of `from("quartz://myGroup/myTimerName?cron=0/1+*+*+*+*+?").process(new SchedulerService());` ? If yes than how ? – Dhaval Patel Jul 02 '15 at 08:38
  • Just add the option to your uri, eg: `from("quartz://myGroup/myTimerName?cron=0/1+*+*+*+*+?&stateful=true").process(new SchedulerService());` – soilworker Jul 02 '15 at 09:13