Singleton pattern with combination of lazy loading and thread safety

前端 未结 5 2000
天涯浪人
天涯浪人 2021-02-03 23:53

I was doing some research about singletons, specifically regarding lazy vs eager initialization of singletons.

An example of eager initialization:

public         


        
5条回答
  •  忘了有多久
    2021-02-04 00:18

    The best way is actually to use the Enum Way:

    public enum Singleton {
        INSTANCE;
        public void execute (String arg) {
                //... perform operation here ...
        }
    }
    

提交回复
热议问题