Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Camel With Quartz - No Concurrent Execution

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.

like image 398
Dhaval Patel Avatar asked Oct 30 '25 17:10

Dhaval Patel


1 Answers

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

like image 176
soilworker Avatar answered Nov 01 '25 06:11

soilworker