You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by shahed <sh...@enoor.com> on 2000/09/15 16:12:28 UTC

Multiple Context Question

Hi,

I am running Tomcat 3.1 with Apache 3.1.12.

In my server.xml I have defined multiple context and the docbase points
to directories under webapps/<context>

My questions are :-

1.
In the web.xml of each context, I run a servlet which constructs a single
static instance of a class which is used in all my jsp pages 
via a getInstance() call.

If I need to modify that class, I need to shutdown and restart tomcat
for the changes to take effect.
Is there a way so that I can just reinitialize a single context ?


2.

The class that I am using above is for connection pooling. I was 
under the impression that all contexts run under the same JVM, so
If I construct a static instance of a class, and refer to it via
a getInstance() method which returns the static instance, I should
get the same object across all web contexts.

But for each context, I seem to be getting a new instance.
Does this mean that each context runs under its own jvm ?

Thanks
Shahed. 


Re: Multiple Context Question

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

> Hi,
>
> I am running Tomcat 3.1 with Apache 3.1.12.
>
> In my server.xml I have defined multiple context and the docbase points
> to directories under webapps/<context>
>
> My questions are :-
>
> 1.
> In the web.xml of each context, I run a servlet which constructs a single
> static instance of a class which is used in all my jsp pages
> via a getInstance() call.
>
> If I need to modify that class, I need to shutdown and restart tomcat
> for the changes to take effect.
> Is there a way so that I can just reinitialize a single context ?
>

If the class file is in WEB-INF/classes or WEB-INF/lib, and you set up
auto-reload support in your server.xml file, you can get single webapps
to
reload under some circumstances.  But see below.

>
> 2.
>
> The class that I am using above is for connection pooling. I was
> under the impression that all contexts run under the same JVM, so
> If I construct a static instance of a class, and refer to it via
> a getInstance() method which returns the static instance, I should
> get the same object across all web contexts.
>
> But for each context, I seem to be getting a new instance.
> Does this mean that each context runs under its own jvm ?
>

It is not running under its own JVM, but each webapp *does* run under
its own
classloader.  Static variables are global only within the scope of a
particular classloader, so each webapp that uses your class gets its own
if
the class was loaded from WEB-INF/classes or WEB-INF/lib.

>
> Thanks
> Shahed.

Craig McClanahan

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat