• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway


Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!