Note that there are some explanatory texts on larger screens.

plurals
  1. POQuartz scheduler running for two times in struts2
    text
    copied!<p>I have scheduled a JOB using Quartz scheduler in my Struts2 web application. Everything is working fine as I expected but the trigger is firing two times : on the specified time. After some research I found That <code>ApplicationContext</code> is loading twice. I found these links are useful. <a href="https://stackoverflow.com/questions/3289181/quartz-spring-crontrigger-fired-more-times-than-configured">Job Triggered twice</a> <a href="https://stackoverflow.com/questions/1464881/defaultannotationhandlermapping-via-contextloaderlistener-instead-of-dispatchers/1464886#1464886">Application Context loading Twice</a> But that was not so descriptive or I am unable to understand that. Please help to deal with this.</p> <p>Will provide the code on Request.</p> <p>My web.xml </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt; &lt;display-name&gt;MyAPP&lt;/display-name&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;index.html&lt;/welcome-file&gt; &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt; &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt; &lt;welcome-file&gt;default.html&lt;/welcome-file&gt; &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt; &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;filter&gt; &lt;filter-name&gt;struts2&lt;/filter-name&gt; &lt;filter-class&gt;org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;struts2&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; &lt;listener&gt; &lt;listener-class&gt; org.apache.struts2.tiles.StrutsTilesListener &lt;/listener-class&gt; &lt;/listener&gt; &lt;context-param&gt; &lt;param-name&gt;tilesDefinitions&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/tiles.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;Login.jsp&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;session-config&gt; &lt;session-timeout&gt;30&lt;/session-timeout&gt; &lt;/session-config&gt; &lt;error-page&gt; &lt;error-code&gt;404&lt;/error-code&gt; &lt;location&gt;/jsp/error/pagenotfound.jsp&lt;/location&gt; &lt;/error-page&gt; &lt;listener&gt; &lt;listener-class&gt; com.MYAPP.listners.QuartzListners &lt;/listener-class&gt; &lt;/listener&gt; &lt;/web-app&gt; </code></pre> <p>My QuartzListner.java</p> <pre><code>public class QuartzListner implements ServletContextListener { private static final Logger log=Logger.getLogger(QuartzListner.class); /* (non-Javadoc) * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent) */ @Override public void contextDestroyed(ServletContextEvent arg0) { // TODO Auto-generated method stub log.info("----Quartz Scheduler destroyer Intialized----"); try{ ServletContext context =arg0.getServletContext(); Scheduler scheduler =(Scheduler)context.getAttribute("DocRevScheduler"); scheduler.shutdown(true); log.info("----Scheduler Shutting downnn ---- "+scheduler.isShutdown()); }catch(Exception se) { log.warn("--Exception while Shutdowning the Scheduler..."+se); se.printStackTrace(); } } /* (non-Javadoc) * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) */ @Override public void contextInitialized(ServletContextEvent arg0) { // TODO Auto-generated method stub log.info("--Qurz Scheduler intialized----"); JobDetail job = JobBuilder.newJob(MailSendingJOB.class) .withIdentity("mailJob", "group1").build(); JobDetail jobDetail =JobBuilder.newJob(DBOperationsJOB.class) .withIdentity("DBJOB", "group2").build(); try { ResourceBundle resource = ResourceBundle.getBundle("resources.application"); Trigger trigger = TriggerBuilder .newTrigger() .withIdentity("anyTriggerName", "group1") .withSchedule( CronScheduleBuilder.cronSchedule(resource.getString("triggerTime"))) .build(); Trigger trigger1 = TriggerBuilder .newTrigger() .withIdentity("sampleTrigger", "group2") .withSchedule( CronScheduleBuilder.cronSchedule(resource.getString("triggetTime"))) .build(); Scheduler scheduler = new StdSchedulerFactory().getScheduler(); scheduler.start(); scheduler.scheduleJob(job, trigger); scheduler.scheduleJob(jobDetail, trigger1); ServletContext context = arg0.getServletContext(); context.setAttribute("MyJOBScheduler", scheduler); } catch (SchedulerException e) { e.printStackTrace(); } } </code></pre> <p>}</p> <p>In My Propertyfile <code>triggerTime=0 19 11 ? * MON *</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload