Yes, but this doesn't work as a generic implementation... what I want to do is write an abstract class that all its subclasses must be singletons... I would like that who extends my class have no need to implement the getInstance() method
On Wed, 2003-02-05 at 16:48, Jacob Kjome wrote: > Hello Felipe, > > just use > > MyClass.class in static contexts. The only issue is that if you > change the class name, you will also have to change any case where you > did MyClass.class to match the new name of the class. > > Jake > > Wednesday, February 05, 2003, 10:52:20 AM, you wrote: > > FS> Very nice reading, but I'm getting convinced that I should not use > FS> Singleton pattern in my case... I just wonder what should I do then :-) > FS> As I said, the method will be called millions of times... so I think > FS> it shouldn't be synch'd (for performance). Certainly I could solve most > FS> of my problems if I could instantiate my singleton in its static > FS> constructor, right? But what I'm really implementing is an abstract > FS> class, and all of its subclasses should be Singletons. I would like to > FS> implement the singleton instantiation routines in the superclass, but I > FS> can't call "this.getClass()" (as in my code sample) from an static > FS> context... > > FS> On Wed, 2003-02-05 at 13:40, Daniel Brown wrote: > >> Here's the best I could do on how to write singletons: > >> > >> > FS> http://developer.java.sun.com/developer/technicalArticles/Programming/single > >> tons/ > >> > >> On the locking front, I can't find anything that suggests that the > FS> semantics > >> of volatile have been changed to make double-checked locking work. > >> > >> I'd love to hear different, or if anyone is aware of anything upcoming > FS> to > >> make the issue more obvious/go away... > >> > >> > -----Original Message----- > >> > From: Felipe Schnack [mailto:[EMAIL PROTECTED]] > >> > Sent: 05 February 2003 12:06 > >> > To: [EMAIL PROTECTED]; Tomcat Users List > >> > Subject: RE: singleton creation (ot) > >> > > >> > > >> > Hmm... nice links! > >> > The first one said about a proposal of solving this problem > FS> through > >> > the use of "volatile" keyword... this was implemented in jdk 1.4? It > >> > seems that site is older than this release... > >> > I'm not sure yet of how I will do it... I would not like to > >> > synchronize the entire method because it'll probably be called > FS> million > >> > of times in my app > >> > > >> > On Wed, 2003-02-05 at 09:42, Daniel Brown wrote: > >> > > The simple answer is 'no'. > >> > > > >> > > For the more complex answer, read the 'Double-Checked Locking is > FS> Broken' > >> > > declaration at: > >> > > > >> > > > FS> http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html > >> > > > >> > > To complicate matters even further, check out the JavaDoc to the > FS> Fast* > >> > > utilities in the Jakarta commons. For example: > >> > > > >> > > > >> > http://jakarta.apache.org/commons/collections/api/org/apache/commo > >> > ns/collect > >> > > ions/FastTreeMap.html > >> > > > >> > > (apologies for the wrap). > >> > > > >> > > Dan. > >> > > > >> > > > -----Original Message----- > >> > > > From: Felipe Schnack [mailto:[EMAIL PROTECTED]] > >> > > > Sent: 05 February 2003 11:21 > >> > > > To: Tomcat Users List > >> > > > Subject: singleton creation (ot) > >> > > > > >> > > > > >> > > > I was wondering... this code is valid to avoid excessive use > FS> of > >> > > > synchronized code? I think so, but we never know :-) > >> > > > This is the default getInstance() method of a singleton > >> > (simplified): > >> > > > > >> > > > public Object getInstance() > >> > > > { > >> > > > if (INSTANCE == null) > >> > > > { > >> > > > synchronized (this) > >> > > > { > >> > > > if (INSTANCE == null) > >> > > > { > >> > > > INSTANCE = this.getClass().newInstance(); > >> > > > } > >> > > > } > >> > > > } > >> > > > return INSTANCE; > >> > > > } > >> > > > > >> > > > -- > >> > > > > >> > > > Felipe Schnack > >> > > > Analista de Sistemas > >> > > > [EMAIL PROTECTED] > >> > > > Cel.: (51)91287530 > >> > > > Linux Counter #281893 > >> > > > > >> > > > Centro Universitário Ritter dos Reis > >> > > > http://www.ritterdosreis.br > >> > > > [EMAIL PROTECTED] > >> > > > Fone/Fax.: (51)32303341 > >> > > > > >> > > > > >> > > > > FS> --------------------------------------------------------------------- > >> > > > To unsubscribe, e-mail: > FS> [EMAIL PROTECTED] > >> > > > For additional commands, e-mail: > FS> [EMAIL PROTECTED] > >> > > > > >> > > > >> > > > >> > > > FS> --------------------------------------------------------------------- > >> > > To unsubscribe, e-mail: [EMAIL PROTECTED] > >> > > For additional commands, e-mail: > FS> [EMAIL PROTECTED] > >> > > > >> > -- > >> > > >> > Felipe Schnack > >> > Analista de Sistemas > >> > [EMAIL PROTECTED] > >> > Cel.: (51)91287530 > >> > Linux Counter #281893 > >> > > >> > Centro Universitário Ritter dos Reis > >> > http://www.ritterdosreis.br > >> > [EMAIL PROTECTED] > >> > Fone/Fax.: (51)32303341 > >> > > >> > > >> > > FS> --------------------------------------------------------------------- > >> > To unsubscribe, e-mail: [EMAIL PROTECTED] > >> > For additional commands, e-mail: [EMAIL PROTECTED] > >> > > >> > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: [EMAIL PROTECTED] > >> For additional commands, e-mail: [EMAIL PROTECTED] > >> > > > > -- > Best regards, > Jacob mailto:[EMAIL PROTECTED] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- Felipe Schnack Analista de Sistemas [EMAIL PROTECTED] Cel.: (51)91287530 Linux Counter #281893 Centro Universitário Ritter dos Reis http://www.ritterdosreis.br [EMAIL PROTECTED] Fone/Fax.: (51)32303341 --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]