title: Is this the wrong way of initializing Singleton classes in Java?
body: <p>I had my singleton class initially like this</p>
  
  <pre><code> private static MqttHandler instance = new MqttHandler();
   private MqttHandler(){};
   public MqttHandler getInstance(){
      return instance;
   }
  </code></pre>
  
  <p>Now in one phone it was working as expected, but in another, seems like it was creating many instances, since whenever I tried to log something, it did log multiple times. I have no idea why. 
  The second time I tried using this</p>
  
  <pre><code>  private MqttHandler instance;
    private MqttHandler(){};
    public MqttHandler getInstance(){
        if(instance==null) instance == new MqttHandler();
        return instance;
    }
  </code></pre>
  
  <p>Seems to be working, at least for now, not sure if its going to crash later, Does this mean that, in my first method, whenever I returned instance, it was calling</p>
  
  <pre><code> new MqttHandler();
  </code></pre>
  
  <p>thus creating new instances all the time? Why would it work on one device correctly, and then refuse completely on a different one?</p>