title: How to use lambda while creating a new Thread?
body: <p>I have below code for demonstrating a Deadlock situation in Java. I am just trying replacing a Runnable object variable with lambda.</p>
  <pre><code>public class DeadLockExample1 {
      public static void main(String[] args)    {
          Shared s1 = new Shared();
          Shared s2 = new Shared();
          Runnable runnable1 = () -&gt; s1.methodOne(s2);
          Runnable runnable2 = () -&gt; s2.methodTwo(s1);
  
          //below two lines works fine as usual
          new Thread(runnable1).start();
          new Thread(runnable2).start();
  
          // if I replace above two lines with below two lines, it runs into stackoverflow error
      //    new Thread(() -&gt; s1.methodOne(s2)).start();
      //    new Thread(() -&gt; s2.methodTwo(s1)).start();
      }
  
      private static class Shared {
          synchronized void methodOne(Shared s)
          {
              s.methodTwo(this);
          }
  
          synchronized void methodTwo(Shared s)
          {
              s.methodOne(this);
          }
      }
  }
  </code></pre>
  <p>What's going wrong here?</p>