This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Starting a scheduler on server start up Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Starting a scheduler on server start up" Watch "Starting a scheduler on server start up" New topic
Author

Starting a scheduler on server start up

shobha devi
Greenhorn

Joined: Mar 11, 2009
Posts: 11
I developed a Java Web Application.
In the application, I wrote a scheduler, which is a java program that has main method, to perform certain operation if criteria is met. Now I want to start the scheduler when the application is started. Can anyone please help me how to accomplish the requirement.
Ashish Hiriadka
Greenhorn

Joined: Feb 27, 2011
Posts: 5
you can use ServletContextListner right??
abani patra
Ranch Hand

Joined: Oct 11, 2011
Posts: 70
Hi,
You can start the scheduler in init method of servlet so that on the 1st request it will be started.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

abani patra wrote:You can start the scheduler in init method of servlet so that on the 1st request it will be started.


You could certainly do that if you were working in an environment which didn't have ServletContextListeners. But if your environment has ServletContextListeners -- which it will unless it has been running without upgrades for the last 8 years or so -- you should use them.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

abani patra wrote:Hi,
You can start the scheduler in init method of servlet so that on the 1st request it will be started.

That was ok in 2002. In modern applications a context listener, as Paul suggested, is the way to go.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Starting a scheduler on server start up
 
Similar Threads
Load Spring parameter From Data Base
Quartz scheduler help
trigger programs to run java batch job
quartz scheduler
scheduler task