Sunday, 17 July 2011

Singleton -the 1.5 way



Reference : Effective Java Edition 2


There are two ways to implement Singleton pattern in Java
1.  public final instance field or static factory method to create/get instance.
2. if you are using Java >= 1.5. You can use Enum for Singleton– this way you get Singleton functionality easily and you don't need to worry about the Serialization.

Sample Code:

  and can use in the following way.

 static DatabaseManager dbMgr=DBUtil.INSTANCE.getDBManager();


cheers....  :-)

1 comment: