jQuery in Action, 3rd edition
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

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "if thread dies finally won Watch "if thread dies finally won New topic

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?
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.

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.
I agree. Here's the link: http://aspose.com/file-tools
subject: if thread dies finally won't execute
It's not a secret anymore!