• Post Reply Bookmark Topic Watch Topic
  • New Topic

Last Thread to finish in a multithreaded program  RSS feed

 
Rajiv Chelsea
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per my understanding the "main" thread is the
last thread to finish execution..

Is the above correct?
 
Angel Taveras
Ranch Hand
Posts: 84
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thing for certain about the main thread it's that it's the entry point of your program and it's the first thread of your program that will be executed. After that
the main thread could end before any other thread; that's, depending of the programming of the other threads.

Regards,
 
Sandeep Sanaboyina
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have any Daemons in your code, they will be the last threads to stop execution.
 
aryan Sharma
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a way to ensure that all the threads have exited when the main thread exits ?? i am not referring to the 'join' concept here....
 
Sandeep Sanaboyina
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make all the other threads Daemons. Or, you can simply call System.exit() at the end of main.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!