Debu Panda of Oracle has written about the Quartz Scheduler, which is the open source equivalent of cron for J2EE. Debu walks you through an example of scheduling a job using the Quartz API.

Quartz is an open source enterprise job scheduler from Open Symphony project. For details and downloading Quartz please look at http://www.quartzscheduler.org/quartz/. You can use Quartz to schedule jobs in your J2EE applications such as EJBs. This article will describe Quartz can be used in your J2EE applications to schedule cron like jobs. This will include how to configure Quartz in J2EE containers taking Oracle Application Server 10g Containers for J2EE (OC4J 9.0.4) as an example.

1) It would be helpful to show an example of how to configure Quartz to work without a custom servlet. It can be done and is probably the most likely way people will use it within a J2EE application. I recently implemented something like this, and had to figure it out for myself since the Quartz docs weren't very explicit. Basically, you-Configure your web app to use the Quartz initializer servlet, loading on startup. For example (from web.xml):

Again, I think this is the most flexible, easy to use way to implement quartz, and I'm surprised it's not documented better. In most systems I use, I don't want to hard-code something like a scheduled process that might be subject to frequent scheduling change.

2) The author mentions the "userThreads" setting for application servers to allow Quartz to use user threads. Unfortunately, I'm kind of thread-dumb, so I don't exactly know what this means or why it's important. What happens if Quartz is deployed without this setting? What implications does this setting have to other aspects of server performance (will it cause a conflict with some other setting)? I actually am in the middle of deploying an app that uses Quartz on OC4J and would like to be aware of the implications and necessity of this setting.

Drew,Thanks for the example without having to use a Custom Servlet. I was creating this for very customers that wanted to use cron type triggers with EJBs. I tried to venture this way but could not make this work for an EJB methods. This works great for Java classes though.

Quartz uses its own thread pools and are not container managed threads and it's cannot use the thread pooling from the container. Even I had problems firing Triggers/Jobs when I disabled User Threads.

Please make sure that you do not set the max threads to very high in the quartz.properies file. According to Quartz doc:"A maximum of 5 should be fine for a typical application".

Thanks for the info on EJBs. I've been using an EJB-less environment. As far as user threads are concerned, right now I only have one job running nightly. I've configured 2 threads. Should I be concerned?

Also, in the deployment environment, the server is running a full 9iAS install, not just the oc4j container. So I can't just run the oc4j jar with a user threads switch. Any ideas on how to enable that setting in the 9iAS server? Perhaps there's a console setting? Also, I'm still unclear if this setting has any impact on any other parts of the system, or if there's any situation I should be aware of that this setting might cause.

A technique I've seen used with Quartz and EJB Methods was to let the Quartz jobs simply send JMS messages that trigger message-bean driven beans. Works great, even if Quartz is embedded within an application server, either using the servlet or - what we did with WebLogic - custom-written startup-classes.

From what I can tell, there's no reason that can't be wrapped in a context listener. That's actually not a bad idea, because then your app is a little more portable. I've found that some servers handle the startup parameter on a servlet (in WEB-INF) differently. If I'm not mistaken, Tomcat treats it as a boolean, and I know that Orion and OC4J treat it as a number, to specify the order of load (I vaguely recall that the servlet spec doesn't force it one way or the other). Using a context listener avoids this issue altogether. Though of course then you'd to deal with the fact that it wouldn't run on older servlet specs.

Thanks for the tip; I may go ahead and change my app to do this. I may even contribute the results back into Quartz.

SEVERE: Error scheduling jobs: nulljava.net.MalformedURLException at java.net.URL.<init>(URL.java:571) at java.net.URL.<init>(URL.java:434) at java.net.URL.<init>(URL.java:383) at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source) at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.commons.digester.Digester.parse(Digester.java:1548) at org.quartz.xml.JobSchedulingDataProcessor.processFile(JobSchedulingDataProcessor.java:369) at org.quartz.xml.JobSchedulingDataProcessor.processFileAndScheduleJobs(JobSchedulingDataProcessor.java:394)

avax.servlet.ServletException: ThreadPool class not specified. at org.quartz.ee.servlet.QuartzInitializerServlet.init(Unknown Source) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1029) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:862) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4013) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4357) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:823) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595) at org.apache.catalina.core.StandardHostDeployer.addChild(StandardHostDeployer.java:903) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:252) at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:256) at org.apache.commons.digester.Rule.end(Rule.java:276) at org.apache.commons.digester.Digester.endElement(Digester.java:1058) at org.apache.catalina.util.CatalinaDigester.endElement(CatalinaDigester.java:76) at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.commons.digester.Digester.parse(Digester.java:1567) at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:488) at org.apache.catalina.core.StandardHost.install(StandardHost.java:863) at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:483) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:349) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091) at org.apache.catalina.core.StandardHost.start(StandardHost.java:789) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478) at org.apache.catalina.core.StandardService.start(StandardService.java:480) at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313) at org.apache.catalina.startup.Catalina.start(Catalina.java:556) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)----- Root Cause -----org.quartz.SchedulerException: ThreadPool class not specified. at org.quartz.impl.StdSchedulerFactory.instantiate(Unknown Source) at org.quartz.impl.StdSchedulerFactory.getScheduler(Unknown Source) at org.quartz.ee.servlet.QuartzInitializerServlet.init(Unknown Source) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1029) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:862) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4013) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4357) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:823) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595) at org.apache.catalina.core.StandardHostDeployer.addChild(StandardHostDeployer.java:903) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:252) at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:256) at org.apache.commons.digester.Rule.end(Rule.java:276) at org.apache.commons.digester.Digester.endElement(Digester.java:1058) at org.apache.catalina.util.CatalinaDigester.endElement(CatalinaDigester.java:76) at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.commons.digester.Digester.parse(Digester.java:1567) at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:488) at org.apache.catalina.core.StandardHost.install(StandardHost.java:863) at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:483) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:349) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091) at org.apache.catalina.core.StandardHost.start(StandardHost.java:789) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478) at org.apache.catalina.core.StandardService.start(StandardService.java:480) at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313) at org.apache.catalina.startup.Catalina.start(Catalina.java:556) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)

2005-03-21 09:42:05 StandardContext[/jsp-examples]ContextListener: contextInitialized()2005-03-21 09:42:05 StandardContext[/jsp-examples]SessionListener: contextInitialized()2005-03-21 09:42:06 StandardContext[/servlets-examples]ContextListener: contextInitialized()2005-03-21 09:42:06 StandardContext[/servlets-examples]SessionListener: contextInitialized()2005-03-21 09:42:06 StandardContext[/dashboard]quartz: Quartz Initializer Servlet loaded, initializing Scheduler...2005-03-21 09:42:06 StandardContext[/dashboard]quartz: configFile ------->> null2005-03-21 09:42:06 StandardContext[/dashboard]quartz: Quartz Scheduler failed to initialize: org.quartz.SchedulerException: ThreadPool class not specified. 2005-03-21 09:42:06 StandardContext[/dashboard]Servlet /dashboard threw load() exceptionjavax.servlet.ServletException: ThreadPool class not specified. at org.quartz.ee.servlet.QuartzInitializerServlet.init(Unknown Source) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1029) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:862) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4013) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4357) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:823) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595) at org.apache.catalina.core.StandardHostDeployer.addChild(StandardHostDeployer.java:903) at sun.reflect.GeneratedMethodAccessor54.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:252) at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:256) at org.apache.commons.digester.Rule.end(Rule.java:276) at org.apache.commons.digester.Digester.endElement(Digester.java:1058) at org.apache.catalina.util.CatalinaDigester.endElement(CatalinaDigester.java:76) at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.commons.digester.Digester.parse(Digester.java:1567) at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:488) at org.apache.catalina.core.StandardHost.install(StandardHost.java:863) at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:483) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:349) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091) at org.apache.catalina.core.StandardHost.start(StandardHost.java:789) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478) at org.apache.catalina.core.StandardService.start(StandardService.java:480) at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313) at org.apache.catalina.startup.Catalina.start(Catalina.java:556) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)----- Root Cause -----org.quartz.SchedulerException: ThreadPool class not specified. at org.quartz.impl.StdSchedulerFactory.instantiate(Unknown Source) at org.quartz.impl.StdSchedulerFactory.getScheduler(Unknown Source) at org.quartz.ee.servlet.QuartzInitializerServlet.init(Unknown Source) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1029) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:862) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4013) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4357) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:823) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595) at org.apache.catalina.core.StandardHostDeployer.addChild(StandardHostDeployer.java:903) at sun.reflect.GeneratedMethodAccessor54.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:252) at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:256) at org.apache.commons.digester.Rule.end(Rule.java:276) at org.apache.commons.digester.Digester.endElement(Digester.java:1058) at org.apache.catalina.util.CatalinaDigester.endElement(CatalinaDigester.java:76) at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.commons.digester.Digester.parse(Digester.java:1567) at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:488) at org.apache.catalina.core.StandardHost.install(StandardHost.java:863) at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:483) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:349) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091) at org.apache.catalina.core.StandardHost.start(StandardHost.java:789) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478) at org.apache.catalina.core.StandardService.start(StandardService.java:480) at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313) at org.apache.catalina.startup.Catalina.start(Catalina.java:556) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)

Drew, I have not tried your method..but sounds promising for what I have to do.I am EXTREMELY confused after reading all the quartz documentations out there(ranging from the opensymphony tutorial, Debu's article, Bosanac's o'reilly article, JLG plugin documentation at http://demo.jgsullivan.com/struts/QuartzPlugIn.html and your input:-)..My brain hurts:) Ignorance is a bliss, ain't it?:)

In my case I have a Struts action class which implements the StatefulJob interface (why struts? Because my whacky customer wants to run the job at his whim and fancy..grrr!-where do these people come from ?? - Well not as a chron job..but just to run it at any point in time). So I did the struts action class implementing the StatefulJob interface. Two birds in one shot..same action file can be used as just a job and also as a chron job (this is what prompted me to look at the sketchy documentation of the JLG plugin mentioned above, but that confused me more..as they mention nothing about how to use the JDBCJobStore in there)

My question is this:- if I use the "quartz-jobs.xml" and set it in the quartz.properties like you(Drew) have suggested...AND if I ALSO use the JDBCJobStore, which settings take precedence...Is that the ones in the "quartz-jobs.xml" or the JDBCJobStore table..

Also what takes precedence if I use the "quartz-jobs.xml" and a RAMJobDataStore?

Hi Drew McAuliffe ,
I am very new to Quartz.I have downloaded quartz-1.6.0.zip(latest) and quartz-1.4.3.zip.I dont know how to use it,not even a single step of installation of quartz. can u plz help me how to use quartz from the begining step by step.i tried by mapping quartz.jar to classpath. i tried by running the examples given in that Zip .. but no use of it..
now am in the beginning stage. i dnt know what to do further and to proceed any more. plz help me in time,, i am under pressure in my company.. so plz help me as soon as possible..
Cheers and Regards,
siva

I have tried to get it running on WebSphere 5.0.2 but I get problems by looking up the EJB. I get:

[2004-04-14 09:30:00:287 CEST] 759ba2be JobRunShell I org.quartz.core.JobRunShell Job SystemStatus Trigger Job.SystemStatus Trigger threw a JobExecutionException: [2004-04-14 09:30:00:287 CEST] 759ba2be JobRunShell I org.quartz.core.JobRunShell TRAS0014I: The following exception was logged org.quartz.JobExecutionException: javax.naming.NameNotFoundException: Name comp/env/ejb not found in context "java:". [See nested exception: javax.naming.NameNotFoundException: Name comp/env/ejb not found in context "java:".] at org.quartz.jobs.ee.ejb.EJBInvokerJob.execute(EJBInvokerJob.java:137) at org.quartz.core.JobRunShell.run(JobRunShell.java:178) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:487)* Nested Exception (Underlying Cause) ---------------javax.naming.NameNotFoundException: Name comp/env/ejb not found in context "java:". at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1638) at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:997) at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:920) at com.ibm.ws.naming.urlbase.UrlContext.lookup(UrlContext.java:1211) at com.ibm.ws.naming.urlbase.UrlContext.lookup(UrlContext.java:1203) at com.ibm.ws.naming.urlbase.UrlContext.lookup(UrlContext.java:1257) at javax.naming.InitialContext.lookup(InitialContext.java:359) at org.quartz.jobs.ee.ejb.EJBInvokerJob.execute(EJBInvokerJob.java:135) at org.quartz.core.JobRunShell.run(JobRunShell.java:178) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:487)

Before I had a regular servlet doing the same thing but triggered by a crontab job. The EJB is there on that JNDI name.

I have removed the 'java:comp/env/' and just have the value from ejb-ref-name in web.xml.Now it can find the EJB but the method I want to use have both input argument and return value. I don't need the return value but I must use the argument. Therefore I have:

java.lang.NoSuchMethodException: forcePollSystems at java.lang.Class.getMethod0(Native Method) at java.lang.Class.getDeclaredMethod(Class.java:1196) at org.quartz.jobs.ee.ejb.EJBInvokerJob.execute(EJBInvokerJob.java:198) at org.quartz.core.JobRunShell.run(JobRunShell.java:178) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:487)

At this moment Quartz is quite unstable and buggy: v 1.3.3 does not execute all jobs which were scheduled to run at the same time, v 1.3.4 fixed the problem but CronTrigger does not work with day-of-week specs.

Quartz bug database suddenly became empty and does not allow submitting new bugs now :((((

Thanks for the great article, I am working on implementing a job scheduler within a J2EE container running on OC4J right now, so this really helps! :-)

Since you're using OC4J over Oracle, I was hoping maybe you also used JDev, and if so, do you know where I can find a userThreads setting within JDev (for when I just run the server on my own computer for development).

For example, I hit the "debug" button to start up the OC4J appserver and deploy the app and run it (on my local machine). Somewhere I must be able to configure it to send that userThreads command line parameter, I just can't find where.

As Christopher, I am using JDev to develope an application which use Quartz to schedule jobs, and I am having some troubles with threads and deadlocks. After reading all documentation and trying all the reasonable combination of properties configuration, I think that my problems is related to the userThreads configuration that Debu mention in his useful article.

So, If someone could help us (Christopher and me), I need to configure JDev to use user threads in debugging mode.

I have found where to configure the '-useThreads' parameter in JDeveloper 10g for run/debug mode. - Select the project which you want to set with the above parameter. - Go to Tools > Project properties... - Select 'J2EE' in the tree of the left panel. - In the box labeled with 'Embedded OC4J Command Line' add at the end of the command the parameter '-useThreads'. The command after that should appear like this: ${java} ${jvm} -classpath ${oc4j.jar} ${java.options} ${memory.archive.flag} ${keep.alive.timeout.flag} ${oracle.dms.sensors.flag} ${oracle.jms.lock.flag} ${oc4j.main.class} -config ${server.xml} -userThreads

Will running Quartz in container work with clustering? Its's started by a servet when each node is started, with the web.xml tag - "load-on-startup" - so there's one quartz instance per node. Does this mean you'll get duplicate jobs?Also, quartz is multi-threaded, so running in a J2EE address space is dubious and requires running the app server with -useThreads to enable it.

The J2EE 1.4 spec makes it clear that the creation of threads from within an enterprise app is at the very least strongly discouraged. Section 6.2.1 makes it pretty clear:

"...For example, if enterprise beans were allowed to manage threads, the J2EE platform could not manage the life cycle of the enterprise beans, and it could not properly manage transactions...."

Section 4.2.1.1 opens the door to creating threads in a webapp, but makes it clear that problems could occur:

"...If a web component creates a thread, the J2EE platform must ensure that the newly created thread is not associated with any JTA transaction...."

So the idea of starting Quartz in a servlet, although it may work in some containers, goes against the intent of the J2EE spec designers, and could break your applications in unforseen ways. You may have to make changes to security policies to enable this, but then you have to be sure you know what you're doing.

I found your article very interesting.And i use quartz for xml file creation scheduling.But i cannot use quartz with log4j !I have to put some jar file in the home/lib directory of the oc4j instance and reference them in the server.xml(init-library path=....) file.But the process can't write the log file.Thank you.

I am planning to use quartz in my next project to run BIG jobs. I mean these may take a bit of time to execute, say 5-10 minutes or so. These jobs do some data extractions and generate a huge data file, which might load up the system. Should there be a problem using quartz for this. The application is simple J2EE with hibernate + spring and no ejbs.

Also, I read in the same message thread that there is a problem in scheduling weekly cron jobs. Is this still a problem. I plan to use quartz for mostly weekly jobs.

I read you comment containing Quartz in J2EE and you described the thing i am planning to do. I want to to use the TimerTask which is implemented in Quartz. My setting values should come from the database(JDBC) and my Bean should start automatically with my JBOSS Server. But I have no clue where i have to start. Maybe you can tell me some steps which may help a little bit. How can I make a Bean or how can I deploy this Bean to the JBoss Server. Those are some questions i delve with! It would be nice if you could answer some :-).

i have configured my quartz and running. my bean method which runs as a scheduled quartz job is as follows::
public void doJob() throws Exception{
TestLocalHome tl = null;
TestLocal th = null;
try{
InitialContext ic = new InitialContext();
tl = (TestLocalHome)ic.lookup("java:comp/env/ejb/Test");
th = tl.create("name");
}catch (Exception e){
System.out.println
e.printStackTrace();
}
}
The method is trying to access another entity bean called Test within the application. I am getting the following exception when this method executes. i have tried looking up the bean like ::
tl = (TestLocalHome)ic.lookup("ejb/Test");
and still it fails to work. Help me please i've been stuck for too long a time trying to solve this.
2/6/07 8:38:50:068 CAT] 00000078 SystemErr R javax.naming.NameNotFoundException: Name comp/env/ejb not found in context "java:".
at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java(Compiled Code))
at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java(Compiled Code))
at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java(Inlined Compiled Code))
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java(Compiled Code))
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java(Compiled Code))
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java(Compiled Code))
at javax.naming.InitialContext.lookup(InitialContext.java(Inlined Compiled Code))
at zw.co.interlife.quartz.QuartzEJBBean.doJob(QuartzEJBBean.java(Compiled Code))
at zw.co.interlife.quartz.EJSRemoteStatelessQuartzEJB_6c8a0236.doJob(EJSRemoteStatelessQuartzEJB_6c8a0236.java(Compiled Code))
at zw.co.interlife.quartz._QuartzEJB_Stub.doJob(_QuartzEJB_Stub.java(Compiled Code))
at sun.reflect.GeneratedMethodAccessor38.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at org.quartz.jobs.ee.ejb.EJBInvokerJob.execute(EJBInvokerJob.java(Compiled Code))
at org.quartz.core.JobRunShell.run(JobRunShell.java(Compiled Code))
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java(Compiled Code))

Hi Foster Akaketwa ,
I am very new to Quartz.I have downloaded quartz-1.6.0.zip(latest) and quartz-1.4.3.zip.I dont know how to use it,not even a single step of installation of quartz. can u plz help me how to use quartz from the begining step by step.i tried by mapping quartz.jar to classpath. i tried by running the examples given in that Zip .. but no use of it..
now am in the beginning stage. i dnt know what to do further and to proceed any more. plz help me in time,, plz help me as soon as possible..
Cheers and Regards,
siva

TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations technology projects - with its network of technology-specific websites, events and online magazines.