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

