• Post Reply Bookmark Topic Watch Topic
  • New Topic

Starting Quartz jobs in a web container  RSS feed

 
David Rocks
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
David Rocks
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets are not the place to to any kind of initialization except for that specific servlet instance.
 
David Rocks
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!