tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felipe Schnack <feli...@ritterdosreis.br>
Subject RE: singleton creation (ot)
Date Wed, 05 Feb 2003 16:52:20 GMT
  Very nice reading, but I'm getting convinced that I should not use
Singleton pattern in my case... I just wonder what should I do then :-)
  As I said, the method will be called millions of times... so I think
it shouldn't be synch'd (for performance). Certainly I could solve most
of my problems if I could instantiate my singleton in its static
constructor, right? But what I'm really implementing is an abstract
class, and all of its subclasses should be Singletons. I would like to
implement the singleton instantiation routines in the superclass, but I
can't call "this.getClass()" (as in my code sample) from an static
context...

On Wed, 2003-02-05 at 13:40, Daniel Brown wrote:
> Here's the best I could do on how to write singletons:
> 
>
http://developer.java.sun.com/developer/technicalArticles/Programming/single
> tons/
> 
> On the locking front, I can't find anything that suggests that the
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
to
> make the issue more obvious/go away...
> 
> > -----Original Message-----
> > From: Felipe Schnack [mailto:felipes@ritterdosreis.br]
> > Sent: 05 February 2003 12:06
> > To: dan@27d.org; Tomcat Users List
> > Subject: RE: singleton creation (ot)
> >
> >
> >   Hmm... nice links!
> >   The first one said about a proposal of solving this problem
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
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
Broken'
> > > declaration at:
> > >
> > >
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
> > >
> > > To complicate matters even further, check out the JavaDoc to the
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:felipes@ritterdosreis.br]
> > > > 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
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
> > > > felipes@ritterdosreis.br
> > > > Cel.: (51)91287530
> > > > Linux Counter #281893
> > > >
> > > > Centro Universitário Ritter dos Reis
> > > > http://www.ritterdosreis.br
> > > > ritter@ritterdosreis.br
> > > > Fone/Fax.: (51)32303341
> > > >
> > > >
> > > >
---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
tomcat-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail:
tomcat-user-help@jakarta.apache.org
> > > >
> > >
> > >
> > >
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
tomcat-user-help@jakarta.apache.org
> > >
> > --
> >
> > Felipe Schnack
> > Analista de Sistemas
> > felipes@ritterdosreis.br
> > Cel.: (51)91287530
> > Linux Counter #281893
> >
> > Centro Universitário Ritter dos Reis
> > http://www.ritterdosreis.br
> > ritter@ritterdosreis.br
> > Fone/Fax.: (51)32303341
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
-- 

Felipe Schnack
Analista de Sistemas
felipes@ritterdosreis.br
Cel.: (51)91287530
Linux Counter #281893

Centro Universitário Ritter dos Reis
http://www.ritterdosreis.br
ritter@ritterdosreis.br
Fone/Fax.: (51)32303341


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message