hi all: See the following question: Which of the following is true regarding main Thread? A) It is the thread from which other "child" threads will be spawned. B) It must be the last thread to finish execution. When the main thread stops, the program terminates. C) It has the highest priority. D) main is not a thread. The answer is A) and B) I understand A),but but I was confused about B). I think the main thread can finish, but the program will keep running until all the user threads which are spawned from the main thread are done. Please help me. Thanks!
Joined: Feb 07, 2001
Hi Anon, The program will terminate when main() thread terminates, even if other threads have not completed. That is why join() method is used to allow completion of other spawned threads before main() thread completes.
Joined: Feb 04, 2001
Anon was right, Niraj... I think you're wrong If main() method spawns a thread, that thread inherits the user-thread status of the original thread. When main() finished, the application will CONTINUE to run until the other thread finishes too, unless the application is force to stop using System.exit. There is nothing special about the original thread (main), it just happened to be the first one to get started for a particular run of an application, and it is treated just like any other user thread. If we want our application to exit when the original thread (main) dies, we can mark all the threads we create as DAEMON threads. So, I think A) correct, B) wrong, (but if we invoking System or Runtime method "Exit", this method terminates the current execution of the JVM). C) wrong, they have the same priority D) wrong. hope this help stevie