Re: [xmlWiki-developers] Problems using singletons in servlets
Brought to you by:
elhugo
From: James J K. <Kal...@ca...> - 2001-10-29 19:00:01
|
>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( 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? >Please let me know if there is any solution for this. >Thank you. Good point. One quick solution would be to descope the role of the object to more of a clearing house of information. If it isn't keeping track of real-time states and resources, then having multiple instances on separate VMs shouldn't cause problems. Of course, at some point its role will shrink to the point of not even being necessary, which is a very real possibility. I guess the important question is: aside from settings and polices, what would a centralized object be useful for (pretending for the moment that a safe singleton could be achieved). Regards, Jim |