Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JVM

 
zaghal mohd
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please explain why no 56 correct and what is the different between this tow answers !!?
merci!
When does the JVM exit?

1-After the main method returns.
2-After all the non demons threads created by the application complete.
3-After all the demon threads created by the application complete
4-When a thread executes System.exit();
5-When an uncaught exception is thrown in a non demon thread.
6-When an uncaught exception is thrown in a demon thread.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In both 5 and 6, there may be other non-demon Threads that are running, so the exception will just be reported and the other Thread(s) will continue.
Bill
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bill:
If other thread(s) are to continue, then JVM does NOT exit. So can we say 5 and 6 are correct answers?
Barkat
 
zaghal mohd
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden As yopu said (there may be other non-demon Threads that are running, so the exception will just be reported and the other Thread(s) will continue.
Bill) does the JVM exit? How (comment)??!
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JVM will ALWAYS exit when someone says "System.exit()" regardless of how many threads (daemon or not) are still alive.
For bonus points, here are a few JVM exit and Garbage Collection (gc) questions for you to think about. They are in the spirit of the exam...
Which of these are true?
1. Once an overridden finalize() method is invoked, there is no way to make the object ineligible for gc
2. All objects that have an overridden finalize() method are guaranteed to have their finalize() called before the JVM shuts down, unless it shuts down because of an error or exception.
3. Objects which have at least one reference referring to them will never be garbage collected.
(in other words, if object 1 has a reference to object 2, then object 2 cannot be garbage collected)
4. Once a finally block is invoked, it will always run to completion.
5.Once a try block is entered, a matching finally block will always be invoked (regardless of the outcome of the try/catch)
have fun.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic