aspose file tools*
The moose likes Servlets and the fly likes Want to call a bean method automatically when server starts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Want to call a bean method automatically when server starts" Watch "Want to call a bean method automatically when server starts" New topic
Author

Want to call a bean method automatically when server starts

Ilyas Ahamed
Greenhorn

Joined: Oct 08, 2012
Posts: 2
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

Joined: Mar 10, 2008
Posts: 1666
    
    7

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.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Want to call a bean method automatically when server starts
 
Similar Threads
Head First EJB - EJBContext question
chat application in swings
Web Services for EJB Session Beans
How to call a class when werver starts
Which two CANNOT directly cause a thread to stop executing?