tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felipe Schnack <feli...@ritterdosreis.br>
Subject singleton creation (ot)
Date Wed, 05 Feb 2003 11:20:49 GMT
  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


Mime
View raw message