title: Class level locking with synchronization block, multiple threads on same instance
body: <p>I have following code where multiple threads are invoking same instance method which is guarded by static object</p>
  <pre><code>package com.data;
  
  class TestThread {
  
  private final static Object object = new Object();
  
  public void myWaitMethod() {
      synchronized (object) {
          System.out.println(&quot;Before a &quot; + Thread.currentThread().getId());
          try {
              object.wait();
          } catch (Exception ignore) {
              System.out.println(Thread.currentThread().getId());
          }
          System.out.println(&quot;After a &quot; + Thread.currentThread().getId());
      }
  }
  
  public void myNotifyMethod() {
      synchronized (object) {
          System.out.println(&quot;Before Notify&quot;);
          object.notifyAll();
          System.out.println(&quot;After b&quot;);
      }
  }
  
  public static void main(String[] args) throws InterruptedException {
      TestThread aa1 = new TestThread();
      new Thread(() -&gt; aa1.myWaitMethod()).start();
      new Thread(() -&gt; aa1.myWaitMethod()).start();
      Thread.sleep(1000);
      System.out.println(&quot;sleep&quot;);
      Thread.sleep(1000);
      aa1.myNotifyMethod();
  }
  }
  </code></pre>
  <p><strong>o/p:</strong></p>
  <pre><code>Before a 12
  Before a 13
  sleep
  Before Notify
  After b
  After a 13
  After a 12
  </code></pre>
  <p>I don't understand why &quot;Before a&quot; twice printed even though the block is synchronized.</p>