title: How to check how many threads are waiting for a synchronized method to become unlocked
body: <p>Is there any way to check how many threads are waiting for a synchronized method to become unlocked?</p>
  
  <p>I would like to know when the thread calls a synchronized method:</p>
  
  <p>1) How many threads are already waiting to call the method?</p>
  
  <p>2) Once the method is called how long it needed to wait for the method to become unlocked?</p>
  
  <hr>
  
  <p>Solution:
  I solved this using stackers answer:</p>
  
  <pre><code>public class LockedClass {
      public static int count;
      public static void measuringClass() throws IOException{
          long startTime = System.currentTimeMillis();
          count++;
          System.out.println("Threads waiting="+count);
          lockedMethod(startTime);
          count--;
          System.out.println("Threads waiting="+count);
      }
      public static synchronized void lockedMethod(long startTime) throws IOException{
          System.out.println("I spent="+(System.currentTimeMillis()-startTime)+" in the queue");
          Hashtable&lt;String, String&gt; params = new Hashtable&lt;String, String&gt;();
          params.put("param1", "test");
          params.put("param2", "12345678");
          String sessionId = Common.getSession(Common.executeHttpRequest(params));
      }
  }
  </code></pre>