wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread" Watch "Thread" New topic


Anon Ning

Joined: Mar 09, 2001
Posts: 19
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
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!
niraj singh
Ranch Hand

Joined: Feb 07, 2001
Posts: 36
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.
Stevie Kaligis
Ranch Hand

Joined: Feb 04, 2001
Posts: 400
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
I agree. Here's the link: http://aspose.com/file-tools
subject: Thread
It's not a secret anymore!