File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes does main thread die?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
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: 41065
    
  43
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?


Ping & DNS - my free Android networking tools app
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
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: 41065
    
  43
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: 320

I agree with the die/terminate issue!!!

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: does main thread die??
 
Similar Threads
INTERRUPTEDEXCEPTION
Daemon Thread
Threads
How to distingish between user thread and daemon thread ?
main thread