Re: [xmlWiki-developers] Problems using singletons in servlets
Brought to you by:
elhugo
From: Hugo G. <xm...@ne...> - 2001-10-29 21:38:04
|
rd...@ly... wrote: > Hi, gang. > > Reading the base clases for our project provided by Jim, I noticed > that the WikiContext class will be implemented as a singleton. > > As far as I know, this is not a trivial implementation in Java actually in Java it is trivial. much easier than in C++ or some claim Smalltalk. Check out the implementation in James Cooper's Java(tm) Design Patterns: A Tutorial. ( also > in C++ if you consider all the multithreading stuff). The main > reason is a singleton is UNIQUE PER JVM. But if you have several > JVMs running on the same server, you end up having several > singletons runing in the same time. That is also true for Servlets. > The whole life cycle for a Servlet object(initialized once) is > valid for the JVM the container is runnning. But again what if you > several containers running on different JVMs? Some of the commercial app servers maintain state across multiple vm's. This is part of their approach to load balancing. In theory if a singleton is instantiated in one vm (which in the servlet API 2.3 the servlet container vm and and server vm are separate but not in previous versions of the api) then that singleton is either shared by all vm's or cloned but it's state is maintained across all vm's. I think that the only real way off figuring if the singleton is problematic or not is to test in on a particular server. -H |