Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Threads  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read in one of the faqs that the below stmt is false:
The JVM runs till the main method exits, even if there are other user threads running.
isnt it true that the program terminates when the main thread dies even tho' other user threads may be executing?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "main thread" is just the Thread used to execute the main method. It can easily start other threads and then die.
A Java application runs until either:
1) all user Threads are finished
2) The System.exit() method is called.
There is nothing magic about the "main" thread.
Bill
 
poorna k
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
poorna
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A VM exits also if all the remaining threads are DEAMON threads.
Ex. Say you created 2 user threads in your main() method, thread1 and thread2 and thread1 is a Deamon thread and thread 2 is not.
If the main thread finished (end of main() method), the VM continues to run.
Now if thread2 stopps the VM stopps immediatly without waiting for thread1 to stop (because it is a Deamon thread).
Hope I'm right.
Lahcen.

Originally posted by William Brogden:
The "main thread" is just the Thread used to execute the main method. It can easily start other threads and then die.
A Java application runs until either:
1) all user Threads are finished
2) The System.exit() method is called.
There is nothing magic about the "main" thread.
Bill



[This message has been edited by Lahcen Mannou (edited October 16, 2000).]
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

However if your main thread is destroyed, say by assigning it to null, then the JVM exits. How ever if you set other self created threads to null, the remaining threads keep running.Say you create a thread A and within A you create another thread B and then set A to null, the B thread will Keep running.
 
please buy this thing and then I get a fat cut of the action:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!