• Post Reply Bookmark Topic Watch Topic
  • New Topic

Finalize???  RSS feed

 
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When Ctrl-c causes an application to be interrupted does the finalize method for all objects get called? If not is there any way of executing something when ctrl-c interrupts an application?
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java doesn't guarantee that finalizers are run, ever -- not on normal termination, let alone abnormal termination. Don't write code that requires finalize() to run for correctness.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at Runtime.addShutdownHook.
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
finalize() is for Java Garbage Collection.
As Java does not guarantee Garbage Collection, don't not rely on Finalize method.
 
Ronnie Phelps
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dude! Runtime.addShutdownHook is exactly what I was looking for.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!