tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "George Sexton" <>
Subject RE: Behaviour of load-on-startup=0
Date Mon, 08 Mar 2004 19:14:30 GMT
Load on startup should really be deprecated because it duplicates
functionality available via context event listeners.

As a warning, there is some variance in servlet engines. The spec says 0
starts before 1, logically -1 should load before 0. In fact, some
containers (like Websphere if I remember correctly) don't process
entries with a value less than 0.

My practical advice to you is to look at context event listeners.

-----Original Message-----
From: Michael Prescott [] 
Sent: Monday, March 08, 2004 10:44 AM
Subject: Behaviour of load-on-startup=0

I stumbled on what I think is a small difference in Tomcat's behaviour
the Servlet spec.  Looking at the code, it seems to affect both Tomcat 4

In short, the servlet specs (2.3 and 2.4) says that a servlet with
<load-on-startup> value set to 0 should load before those with values of
or higher, but Tomcat loads 1+ first, and 0 last.

"The load-on-startup element indicates that this servlet should be
(instantiated and have its init() called) on the startup of the web
application. The optional contents of these element must be an integer
indicating the order in which the servlet should be loaded. If the value
a negative integer, or the element is not present, the container is free
load the servlet whenever it chooses. If the value is a positive integer
0, the container must load and initialize the servlet as the application
deployed. The container must guarantee that servlets marked with lower
integers are loaded before servlets marked with higher integers. The
container may choose the order of loading of servlets with the same
load-on-start-up value."

Here's the first part of loadOnStartup(Container[]). This code is
in Tomcat 4.x ( and 5.x

public void loadOnStartup(Container children[]) {

  // Collect "load on startup" servlets that need to be initialized
  TreeMap map = new TreeMap();
  for (int i = 0; i < children.length; i++) {
    Wrapper wrapper = (Wrapper) children[i];
    int loadOnStartup = wrapper.getLoadOnStartup();
    if (loadOnStartup < 0)
    if (loadOnStartup == 0)     // Arbitrarily put them last
        loadOnStartup = Integer.MAX_VALUE;
    Integer key = new Integer(loadOnStartup);
    ArrayList list = (ArrayList) map.get(key);
    if (list == null) {
        list = new ArrayList();
        map.put(key, list);

It appears the problem would be solved by deleting the lines that read:

if (loadOnStartup == 0)     // Arbitrarily put them last
  loadOnStartup = Integer.MAX_VALUE;


Michael Prescott
Ingenura Inc.
(416) 686-8576
PGP Public Key:

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message