multpile inits being called in Servlet

I am trying to create one thread which will be executed once Jakarta-Tomcat begins execution. To do this I have the following code:

*web.xml*

<servlet>

<servlet-name>initializecontroller</servlet-name>

<servlet-class>roverlook.InitializeController</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

*InitializeController.java*

publicclass InitializeControllerextends HttpServlet{

publicvoid init(ServletConfig config)throws ServletException{

super.init(config);

Daemon.INSTANCE.start();// start daemon thread

}

}

*Daemon.java*

publicclass Daemonextends Thread{

publicstaticfinal Daemon INSTANCE =new Daemon(null);// singleton

publicsynchronizedvoid run (){

while(true){

LoggerCentral.info("Daemon executing required jobs at "+ (new java.util.Date()).toString(),null);

// do work here

try{

Thread.sleep(1000*60);

}catch (InterruptedException e){

LoggerCentral.exception("Daemon:run():sleep interrupted",null);

}

}

}

When I run Jakarta-Tomcat, I can see the Daemon writing once every ~1 minute as expected. However, when I run other Servlets (which aren't related to this) there are additional instances of the Daemon which are apparently created, because I see many writes to the logfile, sometimes only 1 second apart. It seems like the init() function is being called again even though I t should not be.

To simplify things, I just put a System.out.print() statement in init() and it is in fact called multiple times! Putting a similar statement reveals that destroy() is *not* being called.

I'm confused, because I thought init() was supposed to run once - Can anyone help out?

Thanks alot

[3150 byte] By [locksleyu] at [2007-9-30 19:12:57]
# 1

This would happen if your other servlets were subclasses of InitializeController and didn't override the init(ServletConfig) method. I know this is unlikely (you don't see examples of servlets subclassing each other much, so it isn't a widely-used technique), but you could get more information about what's happening by replacing your System.out.println debugging statement you have in the servlet's init() method bynew Exception().printStackTrace();

DrClap at 2007-7-6 23:24:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thank you for the good suggestion - I think I was able to make some progress. The first init() is called in

at roverlook.InitializeController.init(InitializeController.java:37)

at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:918)

....

at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:243)

which looks like normal initialization to me. The second one is:

at roverlook.InitializeController.init(InitializeController.java:37)

at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:918)

....org.apache.catalina.connector.warp.WarpConfigurationHandler.deploy(WarpConfigurationHandler.java:313)

at org.apache.catalina.connector.warp.WarpConfigurationHandler.handle(WarpConfigurationHandler.java:117)

at org.apache.catalina.connector.warp.WarpConnection.run(WarpConnection.java:189)

at java.lang.Thread.run(Thread.java:536)

which makes me think it has to do with the fact that I am using Apache Tomcat as a front end and using the Warp connector. In my httpd.conf file I have the following:

WebAppDeploy roverlook warpConnection /roverlook/

WebAppDeploy roverlook warpConnection /roverlook/jsp/*.jsp

It would appear that this warp connector is causing init() to be called more than once! (could it be in a different JVM?). I need things which are accessed via the connector to share the same space with things in tomcat that load via 'load-on-startup'.

Any additional suggestions? Thanks.

locksleyu at 2007-7-6 23:24:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...