title: Why is synchronized block better than synchronized method?
body: <p>I have started learning synchronization in threading.</p>
  
  <p>Synchronized method: </p>
  
  <pre><code>public class Counter {
  
     private static int count = 0;
  
     public static synchronized int getCount() {
        return count;
     }
  
     public synchronized setCount(int count) {
        this.count = count;
     }
  
  }
  </code></pre>
  
  <p>Synchronized block:</p>
  
  <pre><code>public class Singleton {
  
     private static volatile Singleton _instance;
  
     public static Singleton getInstance() {
        if (_instance == null) {
           synchronized(Singleton.class) {
              if (_instance == null)
                 _instance = new Singleton();
           }
        }
        return _instance;
     }
  }
  </code></pre>
  
  <p>When should I use <code>synchronized</code> method and <code>synchronized</code> block?</p>
  
  <p>Why is <code>synchronized</code> block better than <code>synchronized</code> method ?</p>