Hmm
never had any of the problems you mentioned with my app and I do WAR HOT
reload quite often. I never experienced the behaviour you mentioned on my
Tomcat 5 but maybe thats different for JBoss.
But since you mentioned it I will change it in my app too, so it is
compatible with JBoss too.

Thanks for the tip
;)
Thomas

--------- Original-Nachricht --------
Von: Struts Users Mailing List <[EMAIL PROTECTED]>
An: 'Struts Users Mailing List' <[EMAIL PROTECTED]>, 'Thomas Vogt'
<[EMAIL PROTECTED]>
Betreff: RE: Struts and Quartz Scheduler
Datum: 30/09/04 20:26

> Starting Quartz from a servlet is not a good idea, use a Plugin instead.
> 
> Reason:
> 
> I am running on the JBoss application server, and the threads that Quartz
> creates on startup are attached to the app server when using the servlet
> method. Everything works fine, but when your webapp is shutdown, the
threads
> keep going. The threads do not stop until the app server is stopped. So,
if
> you do a hot deploy (just replace the .ear) of your application, which I
do
> quite often during development, you'll end up with multiples of your jobs
> executing at the same time.
> 
> Using plugin:
> 
> If you use a Struts plugin, the threads stop when the webapp stops, even
> when doing hot deploys. In the plugin, the init() method gets called once
> when Struts starts up and the destroy() method gets called once when
Struts
> shuts down. 


> 
> In my code below, I am called jobs implemented as stateless session beans.
> Your jobs might be implemented differently.
> 
> Code:
> 
> Web.xml: 
> Nothing here because you are not using a servlet
> 
> Struts-config.xml:
> Add this line:
> 
>   &lt;plug-in className=&quot;com.mycompany.myapp.QuartzPlugin&quot; /&gt;
> 
> QuartzPlugin.java:
> 
> package com.mycompany.myapp;
> 
> import javax.servlet.*;
> import javax.servlet.http.*;
> import org.apache.commons.logging.*;
> import org.apache.struts.action.*;
> import org.apache.struts.config.*;
> 
> import org.quartz.*;
> import org.quartz.impl.StdSchedulerFactory;
> import org.quartz.jobs.ee.ejb.EJBInvokerJob;
> 
> import java.util.*;
> 
> public class QuartzPlugin implements PlugIn {
> 
>   private static Log log = LogFactory.getLog(QuartzPlugin.class);
> 
>   private String ECOM_GROUP = &quot;eComGroup&quot;;
> 
>       Scheduler sched;
> 
>   public void init(ActionServlet servlet, ModuleConfig moduleConfig)
>         throws ServletException {
> 
>     log.info(&quot;Quartz starting&quot;);
>     
> //    Scheduler sched;
>     try {
>       sched = StdSchedulerFactory.getDefaultScheduler();
>       sched.start();
>     } catch (Exception e) {
>       log.info(&quot;Quartz Scheduler failed to initialize: &quot; +
e.toString());
>       throw new ServletException(e);
>     }
>     
>     log.info(&quot;Initializing jobs...&quot;);
> 
>     addJob(sched, &quot;Heartbeat&quot;, &quot;HeartbeatJob&quot;,
&quot;execute&quot;, &quot;0 0/15 * * * ?&quot;);
> // every 15 minutes
>     addJob(sched, &quot;ExpiredTrial&quot;, &quot;ExpiredTrialJob&quot;,
&quot;execute&quot;, &quot;0 0 20/24 *
> * ?&quot;); // every day at 8pm
> 
>     log.debug(&quot;Quartz started&quot;);  
>   }
>     
>   private void addJob(Scheduler sched, String jobName, String jndiName,
> String methodName, String timing) {
>     JobDetail jd = new JobDetail(jobName, ECOM_GROUP,
EJBInvokerJob.class);
>     jd.getJobDataMap().put(EJBInvokerJob.EJB_JNDI_NAME_KEY, jndiName);
>     jd.getJobDataMap().put(EJBInvokerJob.EJB_METHOD_KEY, methodName);
>     Object[] jdArgs = new Object[0];
>     jd.getJobDataMap().put(&quot;args&quot;, jdArgs);
>     CronTrigger cronTrigger = new CronTrigger(jobName, ECOM_GROUP);   
>     try {
>       cronTrigger.setCronExpression(timing);
>       sched.scheduleJob(jd, cronTrigger);
>     } catch (Exception e) {
>       e.printStackTrace();
>     }
>   }
>   
>   public void destroy() {
>     log.info(&quot;Quartz stopping&quot;);
> 
>               try {
>                       sched.shutdown();
>               } catch (SchedulerException ex) {
>                       ex.printStackTrace();
>               }
>               sched = null;
>   }
>         
> }
> 
> 
> I think I'll put this into my blog.
> 
> Wiebe de Jong
> http://frontierj.blogspot.com/
> 
> 
> -----Original Message-----
> From: Thomas Vogt [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, September 29, 2004 10:08 PM
> To: Struts Users Mailing List
> Subject: AW: Struts and Quartz Scheduler
> 
> You need a class to be executed as Job
> 
> public final class BerechnungsJob implements Job
> {
>      /* (Kein Javadoc)
>       * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
>       */
>      public void execute(JobExecutionContext context) throws
> JobExecutionException
>      {
>         ...
>      }
> }
> 
> and you need a servlet that looks like this to init the Job Trigger
> 
> 32  /***
> 33   * Die Klasse dient als Listener für den Servlet Container um den
Timer
> im Hintergrund laufen zu lassen.
> 34   *
> 36   * @version Version 1.0 27.08.2004
> 37   */
> 38  
> 39  public class TimerServlet implements Servlet
> 40  {
> 41  
> 42      /***
> 43       * @see javax.servlet.Servlet#init(ServletConfig)
> 44       */
> 45      public void init(ServletConfig arg0) throws ServletException
> 46      {
> 47          SchedulerFactory schedFact = new
> org.quartz.impl.StdSchedulerFactory();
> 48          JobDetail jobDetail = new JobDetail(&quot;Calculation
Timer&quot;,
> &quot;Calculation Timer&quot;, BerechnungsJob.class);
> 49          CronTrigger trigger = new CronTrigger(&quot;Calculation
Timer&quot;,
> &quot;Calculation Timer&quot;);
> 50  
> 51          try
> 52          {
> 53              trigger.setCronExpression(&quot;0 0/5 * * * ?&quot;);
> 54              Scheduler sched = schedFact.getScheduler();
> 55              sched.start();
> 56              sched.scheduleJob(jobDetail, trigger);
> 57          }
> 58          catch (Exception e)
> 59          {
> 60              e.printStackTrace();
> 61          }
> 62      }
> 63  
> 64      /***
> 65       * @see javax.servlet.Servlet#getServletConfig()
> 66       */
> 67      public ServletConfig getServletConfig()
> 68      {
> 69          return null;
> 70      }
> 71  
> 72      /***
> 73       * @see javax.servlet.Servlet#service(ServletRequest,
> ServletResponse)
> 74       */
> 75      public void service(ServletRequest arg0, ServletResponse arg1)
> throws ServletException, IOException
> 76      {
> 77      }
> 78  
> 79      /***
> 80       * @see javax.servlet.Servlet#getServletInfo()
> 81       */
> 82      public String getServletInfo()
> 83      {
> 84          return null;
> 85      }
> 86  
> 87      /***
> 88       * @see javax.servlet.Servlet#destroy()
> 89       */
> 90      public void destroy()
> 91      {
> 92      }
> 93  
> 94  }
> 
> which is to be made public and started in web.xml so it is started on
> deployment.
> 
> Hope this helps
> 
> Thomas
> 
> 
> 
> --------- Original-Nachricht --------
> Von: Struts Users Mailing List &lt;[EMAIL PROTECTED]&gt;
> An: 'Struts Users Mailing List ' &lt;[EMAIL PROTECTED]&gt;
> Betreff: Struts and Quartz Scheduler
> Datum: 30/09/04 06:06
> 
> &gt; Has anyone here integrated Quartz with Struts? I'm having a hard time
> &gt; finding examples on this combination.
> &gt; 
> &gt; I'm using the latest version of Quartz, 1.4.2, and I'm initializing
it in
> &gt; web.xml like this:
> &gt; 
> &gt;  &amp;lt;servlet&amp;gt;
> &gt;          &amp;lt;servlet-name&amp;gt;
> &gt;                  QuartzInitializer
> &gt;          &amp;lt;/servlet-name&amp;gt; 
> &gt;          &amp;lt;display-name&amp;gt;
> &gt;                  Quartz Initializer Servlet
> &gt;          &amp;lt;/display-name&amp;gt; 
> &gt;          &amp;lt;servlet-class&amp;gt;
> &gt;                  org.quartz.ee.servlet.QuartzInitializerServlet
> &gt;          &amp;lt;/servlet-class&amp;gt; 
> &gt;          &amp;lt;load-on-startup&amp;gt;
> &gt;                  1
> &gt;          &amp;lt;/load-on-startup&amp;gt;
> &gt;          &amp;lt;init-param&amp;gt;
> &gt;
> &amp;lt;param-name&amp;gt;shutdown-on-unload&amp;lt;/param-name&amp;gt;
> &gt;                  &amp;lt;param-value&amp;gt;true&amp;lt;/param-value&amp;gt;
> &gt;          &amp;lt;/init-param&amp;gt;
> &gt;  &amp;lt;/servlet&amp;gt;        
> &gt; 
> &gt; Anything you could share with me would be greatly appreciated. If you
have
> a
> &gt; quartz.properties file you could share, info on how you access the
> &gt; QuartInitializerServlet, submit jobs, etc., I'd love to see them.
Sample
> &gt; code would be great.
> &gt; 
> &gt; If you know of a good document that explains it, please let me know
about
> &gt; it.
> &gt; 
> &gt; Thanks a bunch,
> &gt; Brian Barnett
> &gt; 
> &gt; ---------------------------------------------------------------------
> &gt; To unsubscribe, e-mail: [EMAIL PROTECTED]
> &gt; For additional commands, e-mail: [EMAIL PROTECTED]
> &gt; 
> &gt; 
> &gt; 
> 
> ________________________________________________
> Message sent using UebiMiau 2.7.8
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

________________________________________________
Message sent using UebiMiau 2.7.8



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to