You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Matt B <MB...@sourcetechcorp.com> on 2000/05/19 19:59:57 UTC

Loading of WebApps

I have a connectionbroker servlet that is specified to load on startup of
the webapp.
When the web app's Context path does not match the path of the web
application  off
of the webapps dir the servlet is loaded twice.

For example:

 <Context path="/stc2" docBase="webapps/stc2" debug="0" reloadable="true" >
</Context>

will cause one instance of the servlet to be loaded

 <Context path="/stc3" docBase="webapps/stc2" debug="0" reloadable="true" >
</Context>

will cause two instances of the servlet to be loaded.

I'm using 3.1 final on NT under jdk1.2.2

Matt Beckius
Source Technology Corporation
www.sourcetechcorp.com


Re: Loading of WebApps

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Matt B wrote:

> ----- Original Message -----
> From: "Craig R. McClanahan" <Cr...@eng.sun.com>
>
> > That is the way it is supposed to work.  Each context has its own set of
> > objects.  The fact that you are sharing the same document root is not
> relevant
> > to that issue.
> >
> > If you truly want to share objects across web applications in Tomcat, you
> will
> > need to use static methods in a class that is loaded from the System class
> > path.  However, you should be aware that this is not guaranteed to be
> supported
> > in all servlet containers.
>
> Thank you for the quick reply.  However I did not make myself clear in the
> original post.
> I'm not trying to share object accross applications,  what I want is to have
> a web application
> where the context path differs from the docbase path of that context.  What
> happens when
> I name the context path different then the docbase path, it appears that
> tomcat loads the
> webapp twice.  I know this because I have a connectionbroker servlet that is
> specified
> to load on startup and the debug output shows twice.  In additon I can see
> that twice
> the number of db connections are being used.
>

OK, I see what you're up to.

>
> My suspision is that the app is being loading twice - once for the the
> context path in the
> server xml file and once when the application is loaded by default.  This
> only happens
> when the context path differs from the docbase webapp path
>
> for eample:
>
> <Context path="/testpath" docBase="webapps/stc2" debug="0" reloadable="true"
> >  </Context>
>

Yes, this will cause Tomcat to load it twice -- once because of this <Context>
element, and once because Tomcat automatically registers any application it sees
in the "webapps" subdirectory.

Try putting your application somewhere else (i.e. not in "webapps"), and
specifying an absolute pathname for the document base.  That way, the automatic
load will not happen.

>
> Matt Beckius
> Source Technology Corporation
> www.sourcetechcorp.com
>

Craig



Re: Loading of WebApps

Posted by Hans Bergsten <ha...@gefionsoftware.com>.
Matt B wrote:
> 
> ----- Original Message -----
> From: "Craig R. McClanahan" <Cr...@eng.sun.com>
> 
> > That is the way it is supposed to work.  Each context has its own set of
> > objects.  The fact that you are sharing the same document root is not
> relevant
> > to that issue.
> >
> > If you truly want to share objects across web applications in Tomcat, you
> will
> > need to use static methods in a class that is loaded from the System class
> > path.  However, you should be aware that this is not guaranteed to be
> supported
> > in all servlet containers.
> 
> Thank you for the quick reply.  However I did not make myself clear in the
> original post.
> I'm not trying to share object accross applications,  what I want is to have
> a web application
> where the context path differs from the docbase path of that context. 

Then you should not place the application in webapps, because every app
found there is loaded automatically (without any configuration needed in
server.xml). In your case you're also defining a web application in
server.xml (with a different name/context path), so Tomcat will load
the applicaton twice, seing them as different apps.

Hans
-- 
Hans Bergsten		hans@gefionsoftware.com
Gefion Software		http://www.gefionsoftware.com

Re: Loading of WebApps

Posted by Matt B <MB...@sourcetechcorp.com>.
----- Original Message -----
From: "Craig R. McClanahan" <Cr...@eng.sun.com>

> That is the way it is supposed to work.  Each context has its own set of
> objects.  The fact that you are sharing the same document root is not
relevant
> to that issue.
>
> If you truly want to share objects across web applications in Tomcat, you
will
> need to use static methods in a class that is loaded from the System class
> path.  However, you should be aware that this is not guaranteed to be
supported
> in all servlet containers.


Thank you for the quick reply.  However I did not make myself clear in the
original post.
I'm not trying to share object accross applications,  what I want is to have
a web application
where the context path differs from the docbase path of that context.  What
happens when
I name the context path different then the docbase path, it appears that
tomcat loads the
webapp twice.  I know this because I have a connectionbroker servlet that is
specified
to load on startup and the debug output shows twice.  In additon I can see
that twice
the number of db connections are being used.

My suspision is that the app is being loading twice - once for the the
context path in the
server xml file and once when the application is loaded by default.  This
only happens
when the context path differs from the docbase webapp path

for eample:

<Context path="/testpath" docBase="webapps/stc2" debug="0" reloadable="true"
>  </Context>

Matt Beckius
Source Technology Corporation
www.sourcetechcorp.com







Re: Loading of WebApps

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Matt B wrote:

> I have a connectionbroker servlet that is specified to load on startup of
> the webapp.
> When the web app's Context path does not match the path of the web
> application  off
> of the webapps dir the servlet is loaded twice.
>
> For example:
>
>  <Context path="/stc2" docBase="webapps/stc2" debug="0" reloadable="true" >
> </Context>
>
> will cause one instance of the servlet to be loaded
>
>  <Context path="/stc3" docBase="webapps/stc2" debug="0" reloadable="true" >
> </Context>
>
> will cause two instances of the servlet to be loaded.
>
> I'm using 3.1 final on NT under jdk1.2.2
>

That is the way it is supposed to work.  Each context has its own set of
objects.  The fact that you are sharing the same document root is not relevant
to that issue.

If you truly want to share objects across web applications in Tomcat, you will
need to use static methods in a class that is loaded from the System class
path.  However, you should be aware that this is not guaranteed to be supported
in all servlet containers.

>
> Matt Beckius
> Source Technology Corporation
> www.sourcetechcorp.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org