|
From: Daniel P. <po...@ci...> - 2004-02-19 17:15:53
|
Juergen,
We'll give your strategy a shot when we get a chance. Sounds like it
should work. I'll be sure to respond to this list with the results.
Thanks for your help!
Daniel
On Thu, Feb 19, 2004 at 04:54:18PM +0100, j?rgen h?ller [werk3AT] wrote:
> Daniel,
>=20
> As you say, this is most likely caused by the fact that Quartz uses its o=
wn threads. WebSphere seems to associate the JNDI context information with =
container-managed threads; unfortunately, this does not apply to Quartz thr=
eads.
>=20
> However, there's a strategy that should work: pre-locate the JNDI objects=
, and pass the objects to Quartz' job data map. This way, the Quartz job sh=
ould receive the pre-located objects when running in its own thread, not ne=
eding to do a JNDI lookup itself.
>=20
> The Quartz support classes (to be committed within an hour!) provide the =
following:
>=20
> - a SchedulerFactoryBean that sets up a Quartz Scheduler, allowing to reg=
ister JobDetails, Calendars and Triggers with it
>=20
> - convenience subclasses of JobDetail, CronTrigger and SimpleTrigger that=
allow for easy bean-style usage; the latter allow for implicit registratio=
n of an associated JobDetail
>=20
> - a FactoryBean for a JobDetail that invokes a method of an existing obje=
ct, to avoid the need for writing one-line Job implementations that just de=
legate to a business method
>=20
> - a convenience implementation of Quartz' Job interface, applying job dat=
a map entries as bean properties
>=20
> A configuration example:
>=20
> <bean id=3D"scheduler" class=3D"org.springframework.scheduling.quartz.Sc=
hedulerFactoryBean">
> <property name=3D"triggers">
> <list>
> <ref bean=3D"myTrigger1"/>
> <ref bean=3D"myTrigger2"/>
> </list>
> </property>
> </bean>
>=20
> <bean id=3D"myJobDetail1" class=3D"org.springframework.scheduling.quartz=
.JobDetailBean">
> <property name=3D"jobClass"><value>werk3.example.MyJob</value></propert=
y>
> <property name=3D"jobDataAsMap">
> <map>
> <entry key=3D"testBean">
> <bean class=3D"org.springframework.beans.TestBean">
> <property name=3D"age"><value>99</value></property>
> </bean>
> </entry>
> </map>
> </property>
> </bean>
>=20
> <bean id=3D"myJobDetail2" class=3D"org.springframework.scheduling.quartz=
.MethodInvokingJobDetailFactoryBean">
> <property name=3D"targetObject"><ref bean=3D"exampleService"/></propert=
y>
> <property name=3D"targetMethod"><value>doSomething</value></property>
> </bean>
>=20
> <bean id=3D"myTrigger1" class=3D"org.springframework.scheduling.quartz.C=
ronTriggerBean">
> <property name=3D"jobDetail"><ref bean=3D"myJobDetail1"/></property>
> <property name=3D"cronExpression"><value>0/5 * * * * ?</value></propert=
y>
> </bean>
>=20
> <bean id=3D"myTrigger2" class=3D"org.springframework.scheduling.quartz.S=
impleTriggerBean">
> <property name=3D"jobDetail"><ref bean=3D"myJobDetail2"/></property>
> <property name=3D"repeatInterval"><value>1000</value></property>
> </bean>
>=20
> MyJob (as referenced from "myJobDetail1") can be implemented as follows:
>=20
> public static class MyJob extends QuartzJobBean {
>=20
> private TestBean testBean;
>=20
> public void setTestBean(TestBean testBean) {
> this.testBean =3D testBean;
> }
>=20
> protected void executeInternal(JobExecutionContext jobExecutionContext)=
{
> System.out.println("Executing job..." + testBean.getAge());
> }
> }
>=20
> Note that the "testBean" entry in the job data map is automatically appli=
ed as bean property in MyJob.
>=20
> As a side note, I've refactored Colin's MethodInvokingFactoryBean into or=
g.springframework.util.MethodInvoker, with MethodInvokingFactoryBean and Me=
thodInvokingJobDetailFactoryBean as subclasses. They provide exactly the sa=
me invocation capabilities.
>=20
> Juergen
>=20
>=20
> -----Original Message-----
> From: spr...@li...
> [mailto:spr...@li...]On Behalf
> Of Daniel Potter
> Sent: Thursday, February 19, 2004 4:17 PM
> To: spr...@li...
> Subject: Re: [Springframework-developer] Quartz support
>=20
>=20
> Juergen,
> I have a question regarding these classes and/or your general experience
> using Quartz with Spring in an J2EE container. We've run into JNDI
> lookup issues with jobs that attempt to use Spring beans that contain
> references to JNDI resources (thru a JndiObjectFactoryBean). It appears
> the Quartz job doesn't know it's running within the container (even
> though the scheduler is started in the init() method of a servlet), so it=
's
> dependencies fail to locate the default JNDI context (and therefore fail
> to locate their JNDI dependencies). I assume this is because the
> scheduler is running in its own thread, so it doesn't have any implicit
> knowledge of the container. To get around this, we've been
> forced to use a separate Spring config file for the Quartz jobs that
> overrides the default JNDI settings used by the JndiObjectFactoryBean
> like this (as if the job had to connect to JNDI remotely):
>=20
> <!-- JNDI connection information -->
> <bean id=3D"myJndiTemplate"
> class=3D"org.springframework.jndi.JndiTemplate">
> <property name=3D"environment">
> <props>
> <prop
> key=3D"java.naming.factory.initial">com.ibm.websphere.naming.WsnInitialCo=
ntextFactory</prop>
> <prop
> key=3D"java.naming.provider.url">iiop://localhost:9091</prop>
> <prop key=3D"java.naming.security.credentials">user</prop>
> <prop key=3D"java.naming.security.principal">pw</prop>
> </props>
> </property>
> </bean>
>=20
> <!-- QUEUE CONNECTION FACTORY -->
> <bean id=3D"jmsQueueConnectionFactory"
> class=3D"org.springframework.jndi.JndiObjectFactoryBean"
> lazy-init=3D"true">
> <property name=3D"inContainer">
> <value>false</value>
> </property>
> <property name=3D"jndiTemplate">
> <ref local=3D"myJndiTemplate"/>
> </property>
> <property name=3D"jndiName">
> <value>Example/QueueConnectionFactory</value>
> </property>
> </bean>
>=20
> This also requires us to load a separate application context for the
> Quartz jobs that uses these settings, rather than being able to share
> the application context used by the rest of the application.
> =20
> Have you ever run into this issue? Do your support classes get around
> this somehow?
>=20
> Regards,
> Daniel
>=20
> On Wed, Feb 18, 2004 at 11:43:14PM +0100, j?rgen h?ller [werk3AT] wrote:
> > Everybody,
> > =20
> > I've revived my Quartz support classes for Spring today. They emerged f=
rom a job scheduling consulting project I did in autumn 2003. We have concr=
ete needs for this now at werk3AT, thus the revival: It's about quite simpl=
e cron-style scheduling of application jobs.
> > =20
> > The basic idea is to set up a Quartz Scheduler via a SchedulerFactoryBe=
an, also allowing to register scheduled jobs there via a <list> of <refs> t=
o ScheduledJobDefinition beans. A ScheduledJobDefinition is just a simple c=
ombination of a Quartz JobDetail and a Quartz Trigger.
> > =20
> > ScheduledJobDefinition bean implementations include:
> > - DefaultScheduledJobDefinition, allowing to use any implementation of =
Quartz' Job interface with a declaratively configured job data map and cron=
trigger
> > - MethodInvokingJobDefinition, allowing to specify a method of a Spring=
-managed bean to execute as job (completely declarative, without the need f=
or implementing a custom Job object), with a cron trigger.
> > =20
> > Both job definition beans can link in a separate Quartz Trigger instanc=
e instead of a cron expression; DefaultScheduledJobDefinition can also link=
in a separate Quartz JobDetail instance instead of a job class.
> > =20
> > That's all there is: A simple declarative way of using Quartz within Sp=
ring. Typically no rescheduling or the like: All schedules are set up on co=
ntext startup, defined as bean definitions. Of course, you can also fetch t=
he Scheduler instance and perform any custom scheduling, instead of using p=
reconfigured ScheduledJobDefinition beans.
> > =20
> > The typical usage scenario are low-level jobs within an application, li=
ke data synchronization or storage cleanup - all predefined jobs that are j=
ust customized by an administrator. Fits nicely into Spring's application c=
ontext model; most jobs will simply delegate to Spring-managed business obj=
ects.
> > =20
> > I expect to have this polished by the end of the week, as we need it at=
werk3AT quite urgently. I'd like to include this already in Spring 1.0 fin=
al, as it's just 6 pretty simple classes (yes, I know - feature freeze - ne=
ver mind ;-). The main question is where to put it: I suggest "org.springfr=
amework.scheduling.quartz".
> > =20
> > If there are no general objections, I'll commit it by the end of this w=
eek, for review within the next week - still plenty of time before 1.0 fina=
l ;-) Looking forward to your feedback!=20
> > =20
> > Juergen
> > =20
> >=20
> >=20
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=1356&alloc_id438&op=3Dclick
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
>=20
>=20
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id438&op=3Dick
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>=20
>=20
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id438&op=3Dclick
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
|