• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

how to execute some procedure when vm is about to close?  RSS feed

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


How can implement this.
Any comments will be popular.
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are looking for something like java.lang.Runtime#addShutdownHook(Thread hook).
 
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
....and welcome to the Ranch
 
jing hu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Christophe Verré wrote:I think you are looking for something like java.lang.Runtime#addShutdownHook(Thread hook).


Thank you very much.
It is just what i want.
 
Sheriff
Posts: 21459
96
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just be warned that those shutdown hooks are only called when the JVM is exiting properly, by having all non-daemon threads closed (including letting the main method end), calling System.exit(...), or closing a windowed application from the Windows task manager's first tab.

If your JVM is forcefully terminated, by a crash (e.g. caused by a bug in native code) or by terminating the process from the Windows task manager's second tab, it stops right there and then and no shutdown hooks are called.
 
jing hu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Prime wrote:Just be warned that those shutdown hooks are only called when the JVM is exiting properly, by having all non-daemon threads closed (including letting the main method end), calling System.exit(...), or closing a windowed application from the Windows task manager's first tab.

If your JVM is forcefully terminated, by a crash (e.g. caused by a bug in native code) or by terminating the process from the Windows task manager's second tab, it stops right there and then and no shutdown hooks are called.



yeal I get what you say.
this will not have serious impact on my program.
Anyway, Thank you for you remind。
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!