Monday, August 31, 2015

performance issue in singleton

if you synchronize out every method call will take time instead if u put inside once the object is instantiated it will never enter syncronzie block unless u null it
public static ASingleton getInstance(){
       if(instance==null){
           synchronized (mutex){
               if(instance==null) instance= new ASingleton();
           }
       }
       return instance;
   }


No comments:

Post a Comment