title: How can this cause a deadlock?
body: <p>I'm brushing up on my Java have been asked this question in an exercise. How could the following result in a deadlock?</p>
  
  <pre><code>private Object sync = new Object();
  
      public void methodA() throws InterruptedException {
          synchronized(this.sync) {
              Thread.sleep(1000);
          }
      }
  
      public void methodB() throws InterruptedException {
          synchronized(this.sync) {
              this.methodA();
          }
      }
  </code></pre>
  
  <p>My guess is that if methodB calls methodA while it has the Thread.sleep function going, the two method would start cascading and cause an indefinite sleep?</p>
  
  <p>Thoughts?</p>