title: Java Thread synchronization - Thread.sleep() Method Not Working as desired
body: <p>i heard, sleep() will lock the current sync method/block
  But here, when i call sleep() on thread 1, thread 2 is able to access the same block? Can anyone Explain?</p>
  
  <h2>Main.java</h2>
  
  <pre><code>public class Main {     
      public static void main(String args[])
      {
          Thread1 t1 = new Thread1();
          Thread2 t2 = new Thread2();
          System.out.println("going to start t1");
          t1.start();
          System.out.println("going to start t2");
          t2.start();
  
      }
  
  }
  </code></pre>
  
  <p>=====================================================================</p>
  
  <h2>Thread1.java</h2>
  
  <pre><code>public class Thread1 extends Thread{
  
      public void run() { 
          Syncc s1 = new Syncc();
          s1.me("T1:");
      }   
  
  }
  </code></pre>
  
  <p>=====================================================================</p>
  
  <h2>Thread2.java</h2>
  
  <pre><code>public class Thread2 extends Thread{
  
      public void run() { 
          Syncc s2 = new Syncc();
          s2.me("T2:");
      }   
  }
  </code></pre>
  
  <p>=====================================================================</p>
  
  <h2>Syncc.java</h2>
  
  <pre><code>public class Syncc{
  
      public void me(String s){
          synchronized(this){
          for(int i=0; i&lt;=5; i++)
          {
              System.out.println(s+" "+" "+i);
              try {
                  Thread.sleep(10000);
              } catch (InterruptedException e) {              
                  e.printStackTrace();
              }
          }
      }
  }
  }
  </code></pre>
  
  <p>==========================================</p>
  
  <h2>Output:</h2>
  
  <pre><code>going to start t1
  going to start t2
  T2:  0
  T1:  0
  T2:  1
  T1:  1
  T1:  2
  T2:  2
  T1:  3
  T2:  3
  T1:  4
  T2:  4
  T2:  5
  T1:  5
  </code></pre>
  
  <p>BUT according to sleep() method, it should not unlock the current synchronization block right? if so the out put should be..</p>
  
  <p>going to start t1
  going to start t2</p>
  
  <pre><code>T1:  0
  T1:  1
  T1:  2
  T1:  3
  T1:  4
  T1:  5
  T2:  0
  T2:  1
  T2:  2
  T2:  3
  T2:  4
  T2:  5
  </code></pre>
  
  <p>i mean after thread 1 execution only thread 2 should start right?
  Whats the issue? </p>