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:[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 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 > > > --------------------------------------------------------------------- > 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]
