title: Printing Odd and Even number using 2 threads?
body: <p>I have tried this code. But after printing 0 , it doesn't print anything.
  It is blocking due to some lock I think.</p>
  
  <pre><code>public class EvenOdd implements Runnable {
      private Object o = new Object();
      private volatile int i = 0;
  
      public void run() {
          try {
              System.out.println();
              if ( Thread.currentThread().getName().equals( "Even")) {
                  printEven();
              } else {
                  printOdd();
              }
          } catch ( Exception ee) {
              ee.printStackTrace();
          }
      }
  
      private void printEven() throws InterruptedException {
          while ( true) {
              synchronized ( o) {
                  while ( this.i % 2 == 0) {
                      o.wait();
                  }
                  System.out.println( Thread.currentThread().getName() + i);
                  i++;
                  o.notify();
              }
          }
      }
  
      private void printOdd() throws InterruptedException {
          while ( true) {
              synchronized ( o) {
                  while ( this.i % 2 != 0) {
                      o.wait();
                  }
                  System.out.println( Thread.currentThread().getName() + i);
                  i++;
                  o.notify();
              }
          }
      }
  }
  </code></pre>
  
  <p>My TestClass:</p>
  
  <pre><code>EvenOdd x = new EvenOdd();
          new Thread(x,"Even").start();
          new Thread(x,"Odd").start();
  </code></pre>
  
  <p>Where am I wrong?
  Thank.</p>
  
  <p>P.S : I know this type of question has been asked many times , but I want to try by my own.</p>