Wednesday, September 18, 2013

java.util.Date to XMLGregorianCalendar

GregorianCalendar gregCal = new GregorianCalendar();
gregCal.setTime(myDate);
XMLGregorianCalendar date2 =  
            DatatypeFactory.newInstance().newXMLGregorianCalendar(gregCal);

Friday, September 13, 2013

How to avoid Spring Quartz job overlap


Quartz 1.x.x

per javadoc "Stateful jobs are not allowed to execute concurrently, which means new triggers that occur before the completion of the execute(JobExecutionContext jobCtx) method will be delayed."

StatefulJob extends Job and it does not add any new methods, to achieve this behavior make the following changes:
From:
public class MySchedulerJob implements org.quartz.Job {
void execute(JobExecutionContext context) {/* method implementation */}
}
To this:
public class MySchedulerJob implements org.quartz.StatefulJob {
void execute(JobExecutionContext context) {/*method implementation*/}
}

Quartz 2.x
Annotations are used in Quartz 2.x, StatefulJob is deprecated.

@DisallowConcurrentExecution
public class MySchedulerJob implements org.quartz.Job {
void execute(JobExecutionContext context) {/*method implementation*/}
}