File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Want to call a bean method automatically when server starts

 
Ilyas Ahamed
Greenhorn
Posts: 2
  • 0
  • 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: 1951
7
Eclipse IDE Java
  • 0
  • 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: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic