Barry, I am not expecting "new StartRun().start();" to start a new thread, but I am expecting that if I run "new StartRun().start()" at the end of the main method then it should print "start method" in the end and if I run the main method with this line in the middle of these threads then it should print "start method" in the middle. But it always prints "start method" in the beginning.
I have edited my last post as the output written in that was not right earlier.
I want to know,
does main thread finish first and then child threads run???(because in my example "start run" is printed always.
Or there is no specific order for that.
Actually the thing is I am confused about the order in which threads(main, child and daemon) will execute.
Barry, if you know some simple article or tutorial on that then please provide the link.
OK. When your "new StartRun().start();" is before the creation and starting of the three threads it must print out before the threads (neglecting i/o buffer flushing behaviour). Why? Because it runs in the main thread and it must finish before the three threads are created and started.
If your "new StartRun().start();" is between or after the creation and starting of the threads, then you cannot predict where the output will be printed. Or even whether the threads will output in any particular order.
Thread scheduling is implementation dependent, and although you can play around with thread priorities, you cannot, in general, predict the running order of individual threads.
Joined: May 11, 2004
Barry, you mean to say that we can never predict which thread will execute first and which one is later. The only control mechanism we have is thread priorities.