• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Starting a scheduler on server start up

 
shobha devi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use ServletContextListner right??
 
abani patra
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can start the scheduler in init method of servlet so that on the 1st request it will be started.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65125
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic