2 Replies Latest reply: Oct 23, 2012 6:57 AM by EJP RSS

    java multithreading

    970110
      public class Main {
      
          public static void main(String[] args)throws Exception {
              Thread thread1=new Thread(new Runnable()
              {
                  public void run()
                  {
                      System.out.println("Thread1");
                  }
              });
              thread1.join();
              thread1.start();
              for (int i = 0; i < 1000; i++) {
                  System.out.println(i);
              }
          }
      
      }
      Sometimes "Thread1" gets printed even before all the numbers get printed. Any reason for that? Shouldn't Thread1 should wait until main thread gets completed?

      Edited by: 967107 on Oct 23, 2012 5:38 AM