Hi,

Thanks for the help. I took a break for an hour or so (after working on this nearly all day), and came to the same conclusion. I have managed to get it to only initialize once now but it does work as I would expect it to.

Test 1
If autoDeploy="false" and I have a context definition in the server.xml (<Context path="" docBase="/foo/tomcat/webapps/xfly/" debug="0"/>) then it calls contextInitialization twice.


Test 2
if autoDeploy="false" and I have no context in the server.xml file it calls contextInitialization only once but the software is then deployed with the wrong context


Test 3
if I rename the webapp (from webapps/xfly to webapps/ROOT), include a context definition of <Context path="" docBase="" debug="0"/> and leave autoDeploy="false" then it doesn't get deployed at all


Test 4
As test 3 but if I remove the context definition from the server.xml file then it deploys and calls contextInitialization only once.


Test 5
As test 4 but with autoDeploy="true" gives the same result.

Now thats all fine and good as I have a solution to my problem but it does seem to indicate that it's impossible to have a webapp in the hosts appBase directory that is deployed under a different context name from its directory name (well, unless you want it initialized twice). Is this a bug or a feature? Surely it must be fairly simple to check whether a particular webapp has already been deployed (possibly under a different context name) and not deploy it a second time if it has. I don't remember seeing anything in the servlet spec that forbade deploying a webapp twice in a since host but I don't think its what most people would expect.

graham

Shapira, Yoav wrote:

Hi
I bet it's being called once for each time the context is deployed, and
the context is deployed twice because you have autoDeploy on AND an
explicit context declaration in your server.xml/conf directory/WAR.
Turn autoDeploy off and see what happens.

(This would explain the static counter being 1: the counter is static
once per classloader repository, you have two of the same context at
different paths with different classloader repositories).

Yoav Shapira
Millennium Research Informatics




-----Original Message-----
From: Graham Smith [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 10, 2004 12:32 PM
To: [EMAIL PROTECTED]
Subject: contextInitialized being called exactly twice

Hi,

I am absolutely stumped by this problem. For some reason that I can't
fathom the contextInitialized method on a ServletContextListener I have
in one of my web applications is being called twice. Normally this


isn't


a problem since it only causes the load process to take longer but I
have recently added a new section that starts a daemon thread and it
this double call is causing two threads to be created. What is even


more


bizarre is that I have tried using a static int to count the number of
times the method is called but it always returns one. I suspected that
it therefore must be created by a different class loader but a call to
getClass().getClassLoader and a dump (see below) of information would
seem to indicate that it is in fact the same class loader loading the
class. I am using tomcat 5.0.25 on Linux with Java 1.4.2_04. I have


also


performed a thread dump in order to check that it is _really_ being run
twice and sure enough there are two copies of my thread running (again
see extract below).

Any help would be greatly appreciated.

Graham

ClassLoader dump:
----------------------------------------------------
First time it is loaded
----------------------------------------------------
ClassLoader: WebappClassLoader
 delegate: false
 repositories:
----------> Parent Classloader:
StandardClassLoader
 delegate: true
 repositories:
   file:/home/gms/dump/tomcat/shared/classes/
----------> Parent Classloader:
StandardClassLoader
 delegate: true
 repositories:
   file:/home/gms/dump/tomcat/common/classes/
   file:/home/gms/dump/tomcat/common/endorsed/xercesImpl.jar
   file:/home/gms/dump/tomcat/common/endorsed/xmlParserAPIs.jar
   file:/home/gms/dump/tomcat/common/lib/ant.jar
   file:/home/gms/dump/tomcat/common/lib/commons-collections.jar
   file:/home/gms/dump/tomcat/common/lib/commons-dbcp-1.1.jar
   file:/home/gms/dump/tomcat/common/lib/commons-el.jar
   file:/home/gms/dump/tomcat/common/lib/commons-pool-1.1.jar
   file:/home/gms/dump/tomcat/common/lib/jasper-compiler.jar
   file:/home/gms/dump/tomcat/common/lib/jasper-runtime.jar
   file:/home/gms/dump/tomcat/common/lib/jsp-api.jar
   file:/home/gms/dump/tomcat/common/lib/naming-common.jar
   file:/home/gms/dump/tomcat/common/lib/naming-factory.jar
   file:/home/gms/dump/tomcat/common/lib/naming-java.jar
   file:/home/gms/dump/tomcat/common/lib/naming-resources.jar
   file:/home/gms/dump/tomcat/common/lib/servlet-api.jar
----------> Parent Classloader:
[EMAIL PROTECTED]


---------------------------------------------------- Second time it is loaded ----------------------------------------------------

ClassLoader: WebappClassLoader
 delegate: false
 repositories:
----------> Parent Classloader:
StandardClassLoader
 delegate: true
 repositories:
   file:/home/gms/dump/tomcat/shared/classes/
----------> Parent Classloader:
StandardClassLoader
 delegate: true
 repositories:
   file:/home/gms/dump/tomcat/common/classes/
   file:/home/gms/dump/tomcat/common/endorsed/xercesImpl.jar
   file:/home/gms/dump/tomcat/common/endorsed/xmlParserAPIs.jar
   file:/home/gms/dump/tomcat/common/lib/ant.jar
   file:/home/gms/dump/tomcat/common/lib/commons-collections.jar
   file:/home/gms/dump/tomcat/common/lib/commons-dbcp-1.1.jar
   file:/home/gms/dump/tomcat/common/lib/commons-el.jar
   file:/home/gms/dump/tomcat/common/lib/commons-pool-1.1.jar
   file:/home/gms/dump/tomcat/common/lib/jasper-compiler.jar
   file:/home/gms/dump/tomcat/common/lib/jasper-runtime.jar
   file:/home/gms/dump/tomcat/common/lib/jsp-api.jar
   file:/home/gms/dump/tomcat/common/lib/naming-common.jar
   file:/home/gms/dump/tomcat/common/lib/naming-factory.jar
   file:/home/gms/dump/tomcat/common/lib/naming-java.jar
   file:/home/gms/dump/tomcat/common/lib/naming-resources.jar
   file:/home/gms/dump/tomcat/common/lib/servlet-api.jar
----------> Parent Classloader:
[EMAIL PROTECTED]



----------------------------------------------------
Extract of thread dump
----------------------------------------------------

......


"ContainerBackgroundProcessor[StandardEngine[Catalina]]" daemon prio=1
tid=0x0848eb98 nid=0x7d54 waiting on condition [4d90d000..4d90d854]
at java.lang.Thread.sleep(Native Method)
at
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run


(Con


tainerBase.java:1597)
       at java.lang.Thread.run(Thread.java:534)

"category statistics generator" daemon prio=1 tid=0x082e6960 nid=0x7d54
waiting on condition [4e1de000..4e1de854]
at java.lang.Thread.sleep(Native Method)
at
com.crazysquirrel.xfly.category.CategoryStats.run(CategoryStats.java:73


)


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

"directory cleaner" daemon prio=1 tid=0x0852dd30 nid=0x7d54 waiting on
condition [4e15d000..4e15d854]
at java.lang.Thread.sleep(Native Method)
at
com.crazysquirrel.xfly.web.DirectoryCleaner.run(DirectoryCleaner.java:8


0)


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

"category statistics generator" daemon prio=1 tid=0x085072f8 nid=0x7d54
waiting on condition [4e0dc000..4e0dc854]
at java.lang.Thread.sleep(Native Method)
at
com.crazysquirrel.xfly.category.CategoryStats.run(CategoryStats.java:73


)


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

"directory cleaner" daemon prio=1 tid=0x084e7ea8 nid=0x7d54 waiting on
condition [4e05b000..4e05b854]
at java.lang.Thread.sleep(Native Method)
at
com.crazysquirrel.xfly.web.DirectoryCleaner.run(DirectoryCleaner.java:8


0)


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

"Signal Dispatcher" daemon prio=1 tid=0x08096a50 nid=0x7d54 waiting on
condition [0..0]

........

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to