aspose file tools*
The moose likes Servlets and the fly likes How can let servlet alive as long as Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How can let servlet alive as long as Tomcat" Watch "How can let servlet alive as long as Tomcat" New topic
Author

How can let servlet alive as long as Tomcat

yangelq yu
Greenhorn

Joined: Oct 03, 2000
Posts: 8
I create a servlet, and I want it to be called when Tomcat start. This servlet should be alive as long as Tomcat alive.
Any comments will be highly appreciated.
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3879
You probably don't need a Servlet. What you're saying is you want a Java object to be around for the lifetime of Tomcat, right? If so you can just create a singleton in an instance in any of your Servlet.init() methods and make sure that servlet is loaded on startup.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
yangelq yu
Greenhorn

Joined: Oct 03, 2000
Posts: 8
Kyle,
You're right. But, how can I make sure that servlet is loaded on startup?? any configuration in server.xml? pls help.
--y
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12676
    
    5
Like I always say - every servlet / jsp developer should download a copy of the API from java.sun.com
You will find that there is a load-on-startup tag used in the description of a jsp or servlet in the web.xml file.
You can even specify the order in which servlets are loaded.
Here is an example of the use:
<servlet>
<servlet-name>webdav</servlet-name> <servlet-class>org.apache.catalina.servlets.WebdavServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Bill
------------------
author of:


Java Resources at www.wbrogden.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can let servlet alive as long as Tomcat
 
Similar Threads
GC is Back Again
When is a Servlet destroyed?
JMS & Dynamic Queue
ThreadLocal and GC
Is there socket_keepalive equivalent in Weblogic?