Re: RMI, singletons and multiple classloaders in Weblogic
From: John C. Bollinger (jobollin_at_indiana.edu)
Date: 08/09/04
- Next message: Madhur Ahuja: "IllegalMonitorStateException: how to make thread owner"
- Previous message: Steven J Sobol: "Re: Opera with Java?"
- In reply to: Michael Brown: "Re: RMI, singletons and multiple classloaders in Weblogic"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 09 Aug 2004 15:49:00 -0500
[removed weblogic.developer.interest.misc]
Michael Brown wrote:
> "John C. Bollinger" <jobollin@indiana.edu> wrote in message news:<cetk0m$bpp$1@hood.uits.indiana.edu>...
>>>Our app doesn't have any EJBs and it's just
>>>a straightforward web application with a cache of data. There must
>>>necessarily only be one copy of the cache (per server) so I don't see
>>>how this could be done *without* using the singleton pattern.
>>
>>Hogwash. The Singleton pattern is by no means the only way to make an
>>entire application use the same instance of some class, and often it
>>isn't the best way, either. The key is that there needs to be some sort
>>of registry in which the instance is stored. With the Singleton
>>pattern, that registry is within the class itself. Alternatively it
>>could be in some other class: a factory class, for instance, a class
>>especially for the purpose, or (as you mention below) some more
>>general-purpose registry such as JNDI.
>
>
> OK, but surely if you used another class implementing a registry or a
> factory at some point you'd need a static member that stores the
> instance which is subject to exactly the same multiple classloader
> issues with J2EE as the "classic" singleton implementation.
It depends on your application. In almost all cases it is possible to
do it without involving any static variable in the process. In many
cases, however, that would be more trouble than it's worth.
> It would seem that using JNDI is the only surefire way to do this,
> without re-inventing the wheel.
JNDI is a very reliable way to do it, and it involves a minimal amount
of coding. You will probably find, by the way, that the back end of the
JNDI implementation you end up using does not use a static variable to
store the instance :-) .
>>I will keep harping on this as long as such questions keep arising:
>>Singleton is the single most misused design pattern known to
>>programmerdom. It should be used when the class represents something
>>that is fundamentally unique and where that uniqueness NEEDS to be tied
>>to object identity. Those cases are rare. Singleton should NOT be used
>>simply to enforce development-time predictions of suitable uses, or
>>(worse) "because it can be".
>
>
> I think you're being a bit harsh. Sure, Singletons are often misused
> but they are also the most useful pattern from the GOF book. I don't
> agree that cases where their use is valid are rare.
I'm afraid I simply don't agree. I don't agree that the pattern is
broadly useful, and I certainly don't agree that it's the most useful
GoF pattern: I'd nominate one of "Decorator", "Template Method", or
"Factory / Factory Method" for that honor. Honorable mention goes to
"Strategy", "Object Adapter", and "Class Adapter". The award for single
most widely used GoF pattern probably goes to "Iterator", at least in
Java. "Observer" might be in one of my lists if I did more GUI
programming or worked on some kinds of dynamic modeling problems.
"Composite", and "Visitor" both have good uses. "Abstract Factory" is
invaluable for certain kinds of problems. "Singleton"? It's down there
somewhere deeper, as far as I'm concerned.
Cheers,
John Bollinger
jobollin@indiana.edu
- Next message: Madhur Ahuja: "IllegalMonitorStateException: how to make thread owner"
- Previous message: Steven J Sobol: "Re: Opera with Java?"
- In reply to: Michael Brown: "Re: RMI, singletons and multiple classloaders in Weblogic"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|