public class MyObject {
    
    private volatile static MyObject instance;
    
    private MyObject(){}
    
    public static MyObject getInstance(){
        try {
            if(instance != null){
                return instance;
            }else{synchronized ( instance.class) {
                    if(instance == null){
                        instance = new MyObject();
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return instance;
    }

}

 

相关文章:

  • 2021-07-31
  • 2021-06-10
  • 2021-04-13
  • 2022-12-23
  • 2021-12-31
  • 2022-03-12
  • 2022-12-23
  • 2021-10-03
猜你喜欢
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
  • 2022-03-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案