title: Multiple thread to print numbers
body: <p>I'm a student trying to learn Java. I want to print employee ID from 1 to 100 using three threads. I used the code that is shown below.</p>
  
  <h1>My main class:</h1>
  
  <pre><code>public class MainThread {
  
      public static void main(String[] args) {
          PrintThread pr = new PrintThread();
          Thread T1 = new Thread(pr);
          Thread T2 = new Thread(pr);
          Thread T3 = new Thread(pr);
          T1.start();
          T2.start();
          T3.start();
      }
  }
  
  public class PrintThread extends Thread {
  
      private final Object sync = new Object();
  
      public void run() {
          synchronized (sync) {
              for (int i = 1; i &lt;= 101; i++) {
                  System.out.println("Employee ID : " + i);
                  try {
                      Thread.sleep(100);
  
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
          }
  
      }
   }
  </code></pre>
  
  <p>I'm getting output as 1....100 is printed by thread 1 then again by thread 2 and thread 3. </p>
  
  <p>But my intended output is thread 1 printing one,thread 2 printing 2,thread 3 printing 3 and so on.</p>
  
  <p>Please help me to sort this out.!!!</p>