| Author |
How to Start a service automatically when the tomcat starts?
|
Muralidharan Raju
Greenhorn
Joined: Feb 24, 2011
Posts: 25
|
|
Hey folks,
i need to run an application that can run automatically that when the tomcat starts..?
any suggestions...?
|
 |
Kumar Raja
Ranch Hand
Joined: Mar 18, 2010
Posts: 457
|
|
Muralidharan Raju wrote:Hey folks,
i need to run an application that can run automatically that when the tomcat starts..?
any suggestions...?
Hi Muralidharan,
What do you mean by an application here? Since you posted in webservices forum, I assume that you are referring to a webservice. As long as the service is deployed properly in webcontainer, when you start the tomcat, it would automatically starts the service just like any other web application. Please be aware that webservice deployed in webcontainer is nothing but a service wrapped in a servlet which looks for SOAP request over HTTP just like any other servlet.
|
Regards
KumarRaja
|
 |
Ivan Krizsan
Bartender
Joined: Oct 04, 2006
Posts: 2193
|
|
Hi!
One basic approach is to configure a servlet to be eagerly loaded by using the <load-on-startup> element in a <servlet> element in the web.xml deployment descriptor or, if you are using Tomcat 7 (or any other container implementing the servlet 3 specification), the loadOnStartup element in the @WebServlet annotation.
In the servlet that is eagerly loaded, you also need an initialization method - this method will be called when the servlet is loaded, which will be when Tomcat is started.
The following is an example of such a servlet using the new servlet 3 annotations:
Best wishes!
|
My free books and tutorials: http://www.slideshare.net/krizsan
|
 |
Kumar Raja
Ranch Hand
Joined: Mar 18, 2010
Posts: 457
|
|
Hi Ivan,
I'm just curious, if we need to setup load-on-startup explicitly. If the application is deployed, and when the tomcat starts, would this not make the app available implicitly.
|
 |
Ivan Krizsan
Bartender
Joined: Oct 04, 2006
Posts: 2193
|
|
Hi!
If an application is deployed and enabled, the it will automatically be available when Tomcat has started up.
The load-on-startup property facilitates eager loading of servlets. If the servlet is not eagerly loaded, then it will still be loaded when a request that matches its URL patter arrives.
Eager loading enables us to eagerly load a servlet which may require long time to, for instance, acquire resources. This to avoid waiting time when the first request arrives.
Best wishes!
|
 |
 |
|
|
subject: How to Start a service automatically when the tomcat starts?
|
|
|