This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes does main thread die?? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "does main thread die??" Watch "does main thread die??" New topic
Author

does main thread die??

pitambari parekh
Greenhorn

Joined: Jul 06, 2007
Posts: 15
does the main thread die??
If so, how???
please help me with..
Thanks..

Regards,
Pitambari.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35239
    
    7
It's not quite clear to me what you're asking - is it about a Java application, and by "main thread' you mean the one executing the "main" method?

If so, and if by "die" you mean whether the tread is terminated at the end of the method, then the answer is yes. That does not necessarily mean that the application terminates at that point, though. As long as other non-daemon threads are running (which is quite likely if it is a GUI application) then the application will continue to run.

Does that answer your question?


Android appsImageJ pluginsJava web charts
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 318
Ulf, this is not an attempt to hijack, just an attempt to clarify my perception of the question.....

I have seen cases where (mostly the book examples on spinning off threads...) the main method instantiates and starts up threads.... and then just falls to what would NORMALLY be the end of the program.

I am aware that, after starting the other thread(s) the main thread is still a viable thread and if you code something it will continue to execute....BUT...

if you dont continue code in the main thread, does the main thread just drop to some non-dispatchable state and wait on the rest of the threads to die, or does the whole process (and all threads started) die?


------------------------
Bob
SCJP - 86% - June 11, 2009
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35239
    
    7
The main thread does terminate (sounds less dramatic than "die", doesn't it ). But -as mentioned above- that does not mean that the JVM terminates, as long as other non-daemon threads are still around.
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 318

I agree with the die/terminate issue!!!

Thanks!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: does main thread die??
 
Similar Threads
How to distingish between user thread and daemon thread ?
Daemon Thread
INTERRUPTEDEXCEPTION
main thread
Threads