• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


How can implement this.
Any comments will be popular.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are looking for something like java.lang.Runtime#addShutdownHook(Thread hook).
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
....and welcome to the Ranch
 
jing hu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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。
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic