This discussion is archived
2 Replies Latest reply: Oct 23, 2012 4:57 AM by EJP RSS

java multithreading

970110 Newbie
Currently Being Moderated
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

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points