RE: RE: Struts and Quartz Scheduler

2004-09-30 Thread Wiebe de Jong
If you've not had any problems, that is good. Tomcat is probably taking care
of the threads for you and stopping them. Using the plugin is still better
because instead of relying on the app server to do your cleanup, you can
take charge of it yourself.

Wiebe

-Original Message-
From: Thomas Vogt [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 30, 2004 11:56 AM
To: Struts Users Mailing List
Subject: AW: RE: Struts and Quartz Scheduler

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:
> 
>   <plug-in className="com.mycompany.myapp.QuartzPlugin" />
> 
> 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 = "eComGroup";
> 
>   Scheduler sched;
> 
>   public void init(ActionServlet servlet, ModuleConfig moduleConfig)
> throws ServletException {
> 
> log.info("Quartz starting");
> 
> //Scheduler sched;
> try {
>   sched = StdSchedulerFactory.getDefaultScheduler();
>   sched.start();
> } catch (Exception e) {
>   log.info("Quartz Scheduler failed to initialize: " +
e.toString());
>   throw new ServletException(e);
> }
> 
> log.info("Initializing jobs...");
> 
> addJob(sched, "Heartbeat", "HeartbeatJob",
"execute", "0 0/15 * * * ?");
> // every 15 minutes
> addJob(sched, "ExpiredTrial", "ExpiredTrialJob",
"execute", "0 0 20/24 *
> * ?"); // every day at 8pm
> 
> log.debug("Quartz started");  
>   }
> 
>   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("args", 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("Quartz stopping");
> 
>   try {
>   sched.shutdown();
>   } catch (SchedulerException ex) {
>   ex.printStackTrace();
>   }
>   sched = null;
>   }
> 
>

RE: Struts and Quartz Scheduler

2004-09-30 Thread Barnett, Brian W.
Thanks Wiebe. I saw your name on a post or two in the Quartz forum and was
hoping you'd respond to this here. I really appreciate it!

Brian Barnett

-Original Message-
From: Wiebe de Jong [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 30, 2004 12:28 PM
To: 'Struts Users Mailing List'; 'Thomas Vogt'
Subject: RE: Struts and Quartz Scheduler

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:

  

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 = "eComGroup";

Scheduler sched;

  public void init(ActionServlet servlet, ModuleConfig moduleConfig)
throws ServletException {

log.info("Quartz starting");

//  Scheduler sched;
try {
  sched = StdSchedulerFactory.getDefaultScheduler();
  sched.start();
} catch (Exception e) {
  log.info("Quartz Scheduler failed to initialize: " + e.toString());
  throw new ServletException(e);
}

log.info("Initializing jobs...");

addJob(sched, "Heartbeat", "HeartbeatJob", "execute", "0 0/15 * * * ?");
// every 15 minutes
addJob(sched, "ExpiredTrial", "ExpiredTrialJob", "execute", "0 0 20/24 *
* ?"); // every day at 8pm

log.debug("Quartz started");  
  }

  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("args", 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("Quartz stopping");

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("Calculation Timer",
"Calculation Timer", BerechnungsJob.class);
49  

AW: RE: Struts and Quartz Scheduler

2004-09-30 Thread Thomas Vogt
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:
> 
>   <plug-in className="com.mycompany.myapp.QuartzPlugin" />
> 
> 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 = "eComGroup";
> 
>   Scheduler sched;
> 
>   public void init(ActionServlet servlet, ModuleConfig moduleConfig)
> throws ServletException {
> 
> log.info("Quartz starting");
> 
> //Scheduler sched;
> try {
>   sched = StdSchedulerFactory.getDefaultScheduler();
>   sched.start();
> } catch (Exception e) {
>   log.info("Quartz Scheduler failed to initialize: " +
e.toString());
>   throw new ServletException(e);
> }
> 
> log.info("Initializing jobs...");
> 
> addJob(sched, "Heartbeat", "HeartbeatJob",
"execute", "0 0/15 * * * ?");
> // every 15 minutes
> addJob(sched, "ExpiredTrial", "ExpiredTrialJob",
"execute", "0 0 20/24 *
> * ?"); // every day at 8pm
> 
> log.debug("Quartz started");  
>   }
> 
>   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("args", 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("Quartz stopping");
> 
>   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 

RE: Struts and Quartz Scheduler

2004-09-30 Thread Wiebe de Jong
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:

  

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 = "eComGroup";

Scheduler sched;

  public void init(ActionServlet servlet, ModuleConfig moduleConfig)
throws ServletException {

log.info("Quartz starting");

//  Scheduler sched;
try {
  sched = StdSchedulerFactory.getDefaultScheduler();
  sched.start();
} catch (Exception e) {
  log.info("Quartz Scheduler failed to initialize: " + e.toString());
  throw new ServletException(e);
}

log.info("Initializing jobs...");

addJob(sched, "Heartbeat", "HeartbeatJob", "execute", "0 0/15 * * * ?");
// every 15 minutes
addJob(sched, "ExpiredTrial", "ExpiredTrialJob", "execute", "0 0 20/24 *
* ?"); // every day at 8pm

log.debug("Quartz started");  
  }

  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("args", 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("Quartz stopping");

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("Calculation Timer",
"Calculation Timer", BerechnungsJob.class);
49  CronTrigger trigger = new CronTrigger("Calculation Timer",
"Calculation Timer");
50  
51  try
52  {
53  trigger.setCronExpression("0 0/5 * * * ?");
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 get

RE: Struts and Quartz Scheduler

2004-09-30 Thread Mick.Knutson
This works for me:

web.xml

QuartzInitializer

com.baselogic.yoursos.scheduler.QuartzInitializerServlet
1


quartz-config.xml:





















-Original Message-
From: Barnett, Brian W. [mailto:[EMAIL PROTECTED]
Sent: Wednesday, September 29, 2004 8:58 PM
To: 'Struts Users Mailing List '
Subject: Struts and Quartz Scheduler


Has anyone here integrated Quartz with Struts? I'm having a hard time
finding examples on this combination.

I'm using the latest version of Quartz, 1.4.2, and I'm initializing it in
web.xml like this:



QuartzInitializer
 

Quartz Initializer Servlet
 

org.quartz.ee.servlet.QuartzInitializerServlet
 

1


shutdown-on-unload
true

  

Anything you could share with me would be greatly appreciated. If you have a
quartz.properties file you could share, info on how you access the
QuartInitializerServlet, submit jobs, etc., I'd love to see them. Sample
code would be great.

If you know of a good document that explains it, please let me know about
it.

Thanks a bunch,
Brian Barnett

-
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]