title: Why does this empty synchronized block affect the output of the program?
body: <p>So I was just messing around with basic concurrency when I noticed the empty synchronized block shown in the program causes the outputs to sync up. There is nothing in the block, so why does it do this?</p>
  
  <pre><code>public class MainClass {
  
      public static void main(String[] args) throws InterruptedException {
          SyncTest f = new SyncTest();
          f.start();
  
          for (int i = 0; i &lt; 20; i++) {
              System.out.println("MAIN THREAD:" + i);
              Thread.sleep(500);
                 synchronized (f) {
                  for (int t = 0; t &lt; 15; t++) {
                      Thread.sleep(100);
                  }
              }
          }
      }
   }
  </code></pre>
  
  <hr>
  
  <pre><code>class SyncTest extends Thread {
  
      @Override
      public void run() {
          for (int i = 0; i &lt; 10; i++) {
              try {
                  System.out.println("OTHER THREAD: " + i);
                  Thread.sleep(1300);
                  synchronized (this) {} //Why does this have an effect on the output when commented?
              } catch (InterruptedException ex) {}
          }
      }
  }
  </code></pre>