title: Role of System.out.format in Oracle's deadlock example
body: <p>I was going over several deadlock examples and noticed interesting thing while playing with Oracle's sample: <a href="https://docs.oracle.com/javase/tutorial/essential/concurrency/deadlock.html" rel="nofollow noreferrer">https://docs.oracle.com/javase/tutorial/essential/concurrency/deadlock.html</a>.</p>
  
  <p>If you substitute this line:
  System.out.format("%s: %s" + "  has bowed to me!%n", this.name, bower.getName());</p>
  
  <p>with:
  System.out.println(this.name + " has bowed to me! " + bower.getName());</p>
  
  <p>The deadlock will not longer be triggered.</p>
  
  <p>Can someone explain the reason?</p>
  
  <p>Adding the code from the link above for future reference:</p>
  
  <pre><code>public class Deadlock {
      static class Friend {
          private final String name;
          public Friend(String name) {
              this.name = name;
          }
          public String getName() {
              return this.name;
          }
          public synchronized void bow(Friend bower) {
              System.out.format("%s: %s"
                  + "  has bowed to me!%n", 
                  this.name, bower.getName());
              bower.bowBack(this);
          }
          public synchronized void bowBack(Friend bower) {
              System.out.format("%s: %s"
                  + " has bowed back to me!%n",
                  this.name, bower.getName());
          }
      }
  
      public static void main(String[] args) {
          final Friend alphonse =
              new Friend("Alphonse");
          final Friend gaston =
              new Friend("Gaston");
          new Thread(new Runnable() {
              public void run() { alphonse.bow(gaston); }
          }).start();
          new Thread(new Runnable() {
              public void run() { gaston.bow(alphonse); }
          }).start();
      }
  }
  </code></pre>