{
private static final SingletonObj singleton;

// optional - use if you want the initialization to occur as class load
time
// Otherwise, the initialization will occur at first call to
getSingleton();

// static initialization at load time
static {
    getSingelton ()/
}


private SingletonObj ()
{
  super ();
  singleton = this;
}

public static synchronized SingletonObj getSingleton ()
{
  if ( singleton == null )
  {
    new SingletonObj();
  }
  return singleton;
}


}


On Fri, 2005-08-05 at 20:11 -0700, Ming Han wrote:
> You can use Singleton pattern, but care must be taken. 
> 
> For example
> 
> if ( singleton == null )
> {
>    singleton = new SingletonObj();
> }
> 
> There might be a case where few thread running concurrently on the null
> checking, then multiple singleton object will be created more than one.
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 
> ---------------------------------------------------------------------
> 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]

Reply via email to