• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to Start a service automatically when the tomcat starts?

 
Greenhorn
Posts: 25
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey folks,

i need to run an application that can run automatically that when the tomcat starts..?
any suggestions...?
 
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Kumar Raja
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic