Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes if thread dies finally won't execute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "if thread dies finally won Watch "if thread dies finally won New topic
Author

if thread dies finally won't execute

Rick Reumann
Ranch Hand

Joined: Apr 03, 2001
Posts: 281
One place I have in my notes I have the only thing stopping finally is system.exit() but I also have in another portion of notes that a thread dying could also stop it.
I take it this means that if a Thread object is started with a finally in it and it happens to be a Daemon thread, that it's possible that the main could die and terminate this daemon thread before it's finally would get executed? Is this correct?
Thanks.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Hmmm... Seems like another perfect chance to use the compiler to answer a question. Check out this code:

I guess this lets you draw your own conclusions, but it sure looks like you're right to me.
Corey


SCJP Tipline, etc.
Rick Reumann
Ranch Hand

Joined: Apr 03, 2001
Posts: 281
Thanks Corey! And you are right I should have written code to test this. I apologize. Scrambling around through my many notes here on my last day of studying has me a bit frazzled. Thanks for not flaming my slackness too badly
Your code was perfect.
 
GeeCON Prague 2014
 
subject: if thread dies finally won't execute