This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Servlets and the fly likes Starting Quartz jobs in a web container Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Starting Quartz jobs in a web container" Watch "Starting Quartz jobs in a web container" New topic
Author

Starting Quartz jobs in a web container

David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 160
Hi,

I have been starting quartz jobs in a servlet but this has been causing problems as the servlet is getting init'ed twice. I know starting thread/processes in a servlet is not recomended in the J2EE spec.

Is there a better way to do this? Something that does not go against the spec? The docs seem to say do it in a servlet but we really dont want to do this.

TIA

tomcat 6.0.20 / JDK 1.7
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

I'm not whether to move this to Other Open Source Projects or Servlets, but I'm leaning more towards the latter. So here we go!


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 160
Got it, when you start an eclipse project with a context of ROOT it starts 2 contexts, one ROOT and one with a name of an empty string. This seems to be a bug.

So the servlet gets made twice and 2 jobs get started.

I just hacked it for now and when the context is ROOT I don't start the job.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

Even so you might be better advised to write a ServletContextListener and start the Quartz job in its contextInitialized method. That way you won't bump into cases later where the container decides for some reason that it needs two instances of your servlet.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56179
    
  13

Servlets are not the place to to any kind of initialization except for that specific servlet instance.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 160
Paul Clapham wrote:Even so you might be better advised to write a ServletContextListener and start the Quartz job in its contextInitialized method. That way you won't bump into cases later where the container decides for some reason that it needs two instances of your servlet.


I'll probably do that actually, seems a bit shocking that Quartz document this as standard pratice.

I once started a big fight in a company I was consulting for, they had got an outside consultancy to write a large trading platform and I was asked to review it, when I found out the processes were all started in a servlet I told the client this was strictly not allowed then walked away as the contracts and lawyers got brought out.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel
 
subject: Starting Quartz jobs in a web container
 
Similar Threads
Tomcat and timer services
Job scheduling or Orchestration of Java processes ?
Jax-ws Oneway WebService not behaving as expected
emaill reminders
how Scheduling Jobs in a Java Web Application