Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Want to call a bean method automatically when server starts

 
Ilyas Ahamed
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Want to call a bean method automatically when server starts.
The approach taken is:

1. Call the servlet MyServlet at load-on-startup
2. In MyServlet.init() call the bean method after x seconds. This time is controlled by java.util.Timer and TimerTask.


Is this approach correct?
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on the deployment environment. For instance, if you have a complete JEE 5 or 6 profile available it would be more appropriate to utilize the timer service. However in a simple servlet container like Tomcat there is no such facility, and you could solve it the way you described, or you could use a job scheduler like Quartz, although in your case that seems like overkill.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64847
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All this timer talk is nonsense. Use a context listener. Calling a servlet at startup to perform initialization is like trying to cut fruit with a toothbrush.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic