title: Codes are not executed sequentially regarding threading and synchronization
body: <p>I have the following code:</p>
  <pre><code>public static void main(String[] args) {
      final String s = &quot;&quot;;
      Thread t = new Thread() {
          public void run() {
              try {
                  Thread.currentThread().sleep(3000);
              } catch (InterruptedException ex) {
                  System.out.println(&quot;111&quot;);
              }
              System.err.println(&quot;Waiting for s&quot;);
              synchronized (s) {
                  System.err.println(&quot;got s&quot;);
              }
              System.out.println(&quot;last&quot;);
          }
      };
  
      t.start();
      synchronized (s) {
          t.interrupt();
          s.notifyAll();
      }
  
  
      try {
          Thread.currentThread()
                .sleep(2000);
      } catch (InterruptedException e) {
          e.printStackTrace();
      }
      System.out.println(&quot;222&quot;);
  
  }
  </code></pre>
  <p>The output is always:</p>
  <pre><code>111
  
  last
  
  Waiting for s
  
  got s
  
  222
  
  Process finished with exit code 0
  </code></pre>
  <p>I don't understand how could the 'last' get printed before 'waiting for s' and 'got s'??
  (why the lines are not executed sequentially?)</p>