You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ray Tayek <rt...@attbi.com> on 2002/04/11 00:56:23 UTC

global singleton across multiple engines?

hi, i need to have a global singleton that is a singleton across all 
instances of (tomcat) servlet engines.

is there an engine context in tomcat that i can access?

does this singleton work across virtual hosts?

how does this work across multple jvm's on the same machine (or does this 
not happen)?

how about when you are load balancing across different physical nodes? - do 
you need to have some system semaphore on one of the nodes to prevent 
multiple instances?

afaict so far, restarting a context, takes down all of the classes in the 
context and putting copy of singleton into a different context, seems to 
cause two instances to be created.

any pointers would be appreciated.

thanks

---
ray tayek http://home.attbi.com/~rtayek/
actively seeking telecommuting work
vice chair orange county java users group http://www.ocjug.org/ 
mailto:chair@ocjug.org
hate spam? http://samspade.org/ssw/


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: global singleton across multiple engines?

Posted by Ray Tayek <rt...@attbi.com>.
At 08:32 PM 4/10/02 -0700, you wrote:
>At 09:58 PM 4/10/02 -0400, you wrote:
>>Try RMI.  ...
>that sounds like a good way to solve the problem with different nodes.
>
>>Sharing across different contexts within the same Tomcat engine is a 
>>different matter. ...
>it looks like a different class loader is used  ...

according to jason hunter, each web app (context) has its classes loaded by 
a different class loader. he claims that if i put the class to be shared in 
the server_root/classes, then it wll be found. this does not seem to work 
under tomcat 4.0.1 as he tries to load other contexts first and throws a " 
... ----- Root Cause ----- java.lang.NoClassDefFoundError: 
Singleton       at .<clinit>(S.java:28) ".

now the server_root context is first in the the server.xml file, but it is 
commented out as follows:

         <!-- Tomcat Root Context -->
         <!--
           <Context path="" docBase="ROOT" debug="0"/>
         -->
so that's maybe why he can not find the class.

however, uncommenting this throws the same result (but it waits until you 
try to load on of the servlets that wants the singleton.

how is this supposed to work?

thanks


>>Ray Tayek wrote:
>>
>>>hi, i need to have a global singleton that is a singleton across all 
>>>instances of (tomcat) servlet engines.
>>>is there an engine context in tomcat that i can access?
>>>does this singleton work across virtual hosts?
>>>how does this work across multple jvm's on the same machine (or does 
>>>this not happen)?
>>>how about when you are load balancing across different physical nodes? - 
>>>do you need to have some system semaphore on one of the nodes to prevent 
>>>multiple instances?
>>>afaict so far, restarting a context, takes down all of the classes in 
>>>the context and putting copy of singleton into a different context, 
>>>seems to cause two instances to be created.
>>>any pointers would be appreciated. ...
>>...
>
>---
>ray tayek http://home.attbi.com/~rtayek/
>actively seeking telecommuting work
>vice chair orange county java users group http://www.ocjug.org/ 
>mailto:chair@ocjug.org
>hate spam? http://samspade.org/ssw/
>
>
>--
>To unsubscribe:   <ma...@jakarta.apache.org>
>For additional commands: <ma...@jakarta.apache.org>
>Troubles with the list: <ma...@jakarta.apache.org>

---
ray tayek http://home.attbi.com/~rtayek/
actively seeking telecommuting work
vice chair orange county java users group http://www.ocjug.org/ 
mailto:chair@ocjug.org
hate spam? http://samspade.org/ssw/


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: global singleton across multiple engines?

Posted by Ray Tayek <rt...@attbi.com>.
At 09:58 PM 4/10/02 -0400, you wrote:
>Try RMI.  You cannot have an instance of a class shared across multiple 
>JVMs (= multiple instances of Tomcat running).  But you might be able to 
>set up an RMI server with a singleton instance of a Remote object.

that sounds like a good way to solve the problem with different nodes.

>Sharing across different contexts within the same Tomcat engine is a 
>different matter.  That ought to work as long as the class is loaded by 
>the same ClassLoader instance used by each context to load classes.  How 
>to control that is beyond me.

it looks like a different class loader is used (or different jvm's - i am 
on a linux box so i see many processes (but they are really threads of one 
parent process, so i am guessing one jvm and multiple class loaders)).

is there some way to make tomcat use the same class loader?

thanks

>Ray Tayek wrote:
>
>>hi, i need to have a global singleton that is a singleton across all 
>>instances of (tomcat) servlet engines.
>>is there an engine context in tomcat that i can access?
>>does this singleton work across virtual hosts?
>>how does this work across multple jvm's on the same machine (or does this 
>>not happen)?
>>how about when you are load balancing across different physical nodes? - 
>>do you need to have some system semaphore on one of the nodes to prevent 
>>multiple instances?
>>afaict so far, restarting a context, takes down all of the classes in the 
>>context and putting copy of singleton into a different context, seems to 
>>cause two instances to be created.
>>any pointers would be appreciated. ...
>...

---
ray tayek http://home.attbi.com/~rtayek/
actively seeking telecommuting work
vice chair orange county java users group http://www.ocjug.org/ 
mailto:chair@ocjug.org
hate spam? http://samspade.org/ssw/


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: global singleton across multiple engines?

Posted by Jeffrey Bonevich <bo...@telocity.com>.
Try RMI.  You cannot have an instance of a class shared across multiple 
JVMs (= multiple instances of Tomcat running).  But you might be able to 
set up an RMI server with a singleton instance of a Remote object.

Sharing across different contexts within the same Tomcat engine is a 
different matter.  That ought to work as long as the class is loaded by 
the same ClassLoader instance used by each context to load classes.  How 
to control that is beyond me.

jeff

Ray Tayek wrote:

> hi, i need to have a global singleton that is a singleton across all 
> instances of (tomcat) servlet engines.
> 
> is there an engine context in tomcat that i can access?
> 
> does this singleton work across virtual hosts?
> 
> how does this work across multple jvm's on the same machine (or does 
> this not happen)?
> 
> how about when you are load balancing across different physical nodes? - 
> do you need to have some system semaphore on one of the nodes to prevent 
> multiple instances?
> 
> afaict so far, restarting a context, takes down all of the classes in 
> the context and putting copy of singleton into a different context, 
> seems to cause two instances to be created.
> 
> any pointers would be appreciated.
> 
> thanks
> 
> ---
> ray tayek http://home.attbi.com/~rtayek/
> actively seeking telecommuting work
> vice chair orange county java users group http://www.ocjug.org/ 
> mailto:chair@ocjug.org
> hate spam? http://samspade.org/ssw/
> 
> 
> -- 
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
> 
> 
> 


-- 
Jeffrey Bonevich
Ann Arbor, Michigan
bonevich@telocity.com
http://www.bonevich.com

Hwæt! Wë Gär-Dena   in geär-dagum,
peod-cyninga,       prym gefrünon,
hü ða aepelingas   ellen fremedon!


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>