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 12:05:45 GMT
  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/commons/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


Mime
View raw message