You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rachel Greenham <ra...@enetgroup.co.uk> on 2000/07/28 19:08:16 UTC
load-on-startup servlet being initialised twice
... it looks like a Tomcat bug:
Platform: SuSE Linux 6.4 kernel 2.2.16, SUN JDK-SE 1.2.2 (green threads,
nojit), Jakarta-Tomcat 3.1.
We're in the process of porting our quite large web application from the old
Servlet 2.0 based Apache JServ up to run on Tomcat. Things are going well -
but we have a servlet that needs to be initialised on startup, so I've put a
<servlet> tag into the WEB_INF/web.xml file, and put a
<load-on-startup>1</load-on-startup> in there.
It does start... but twice. In fact, I then put a check in to try to force
it not to initialise twice, like this:
public class StartupServlet extends HttpServlet
{
private boolean initrun = false;
public void init(ServletConfig config) throws ServletException // keeping
JSDK2.0 compatibility for now
{
if (initrun) return;
super.init();
System.out.println("We're off!");
initrun = true;
}
}
And given that, the body of the init method is still being run, ie: we get
"We're off" twice, so it looks like the servlet class is actually being
instantiated twice, with a resultant resource-leak. The site then proceeds
to run normally, but it's clearly not right, is it?
It didn't do this under JSDK2.0, and I put a stack trace into this method,
and it's definitely getting called by Tomcat itself in exactly the same way
each time, not getting called again by our own code. ie, this:
public class StartupServlet extends HttpServlet
{
private boolean initrun = false;
public void init(ServletConfig config) throws ServletException // keeping
JSDK2.0 compatibility for now
{
if (initrun) return;
super.init();
Exception e = new Exception("wibble");
e.printStackTrace();
// too lazy to learn a neater way :-)
System.out.println("We're off!"); // not the real code
initrun = true;
}
}
produces this, regardless of the initrun stuff:
Starting tomcat. Check logs/tomcat.log for error messages
java.lang.Exception: wibble
at
com.enetsoftware.esparto.servlets.StartupServlet.init(StartupServlet.java:73)
at
org.apache.tomcat.core.ServletWrapper.initServlet(ServletWrapper.java:315)
at
org.apache.tomcat.core.ServletWrapper.loadServlet(ServletWrapper.java:276)
at
org.apache.tomcat.context.LoadOnStartupInterceptor.contextInit(LoadOnStartupInterceptor.java:132)
at
org.apache.tomcat.core.ContextManager.initContext(ContextManager.java:227)
at
org.apache.tomcat.core.ContextManager.init(ContextManager.java:201)
at org.apache.tomcat.startup.Tomcat.execute(Tomcat.java:156)
at org.apache.tomcat.startup.Tomcat.main(Tomcat.java:163)
Fri Jul 28 17:34:20 GMT+01:00 2000 Esparto started
memory usage: 68343104 free / 83886072 total
java.lang.Exception: wibble
at
com.enetsoftware.esparto.servlets.StartupServlet.init(StartupServlet.java:73)
at
org.apache.tomcat.core.ServletWrapper.initServlet(ServletWrapper.java:315)
at
org.apache.tomcat.core.ServletWrapper.loadServlet(ServletWrapper.java:276)
at
org.apache.tomcat.context.LoadOnStartupInterceptor.contextInit(LoadOnStartupInterceptor.java:132)
at
org.apache.tomcat.core.ContextManager.initContext(ContextManager.java:227)
at
org.apache.tomcat.core.ContextManager.init(ContextManager.java:201)
at org.apache.tomcat.startup.Tomcat.execute(Tomcat.java:156)
at org.apache.tomcat.startup.Tomcat.main(Tomcat.java:163)
Fri Jul 28 17:34:22 GMT+01:00 2000 Esparto started
memory usage: 67292512 free / 83886072 total
rachel@pell:~/esparto/esparto2 > ~/jakarta-tomcat/bin/tomcat.sh stop
Is it a bug in Tomcat?
By the way, if you don't give a number to <load-on-startup> (ie: you give
<load-on-startup />) you get NumberFormatExceptions on startup, whereas the
Sun spec says that the number is optional.
--
Rachel
Re: load-on-startup servlet being initialised twice
Posted by Rachel Greenham <ra...@enetgroup.co.uk>.
Rachel Greenham wrote:
>
> ... it looks like a Tomcat bug:
just to add to my previous - I'm getting the same behaviour out of Tomcat
3.2 beta 2
--
Rachel