Quartz Cron Job Executing Twice
nathandennis Jul 8, 2009 8:19 AMi have a project, unfortunately that has already gone into production, where it was recently discovered that the all our quartz jobs were executing twice.... i can't find anything on google or in the forum where others have experienced this behavior when not in a cluster,,, which we are not.
jboss 4.2.2
seam 2.0.1.GA
some code
components.xml
<!-- Install the QuartzDispatcher --> <async:quartz-dispatcher/>
scheduler.... it would appear the problem is here
import java.util.Calendar; import java.util.Date; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Observer; import org.jboss.seam.annotations.Transactional; import org.jboss.seam.async.QuartzTriggerHandle; import org.jboss.seam.log.Log; @Transactional @Name("startTimecap") public class StartTimecap { @Logger private Log log; @In TimecapProcessor timecapProcessor; /** * This is called by seam after initialization * has finished. */ @Observer("org.jboss.seam.postInitialization") public void observer() { try { log.info("Trying to Start Timecap Cron Job"); Calendar cal = Calendar.getInstance (); cal.set (2040, Calendar.MAY, 10); QuartzTriggerHandle handle = timecapProcessor.scheduleTimecapQue(new Date(), "0 4 2 * * ?", cal.getTime()); } catch(Exception e) { e.printStackTrace(); log.info("Operation Failed"); } } }
this is executed twice
@Name("timecapProcessor") @AutoCreate public class TimecapProcessor { @Logger Log log; @In EntityManager entityManager; @SuppressWarnings("unchecked") @Asynchronous @Transactional @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public QuartzTriggerHandle scheduleTimecapQue(@Expiration Date when, @IntervalCron String cron, @FinalExpiration Date endDate){ log.info("\n\n\n\n-------------------------------------" + "Scheduler Started, Executing Timecap Job ----------------\n\n\n\n"); //do your processing here return null; } }
im not sure if this is a bug or what.. i had to upgrade the version of seams several times over the course of the project.
hopefully someone will have seen this before or possibly have a hint as to what is going on.
i'm not beyond writing something that will look to see if the job is already scheduled if someone could point me in the right direction.
any help would be greatly appreciated.