Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invoking Java Program Before JVM Stops

 
Steven Wong
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If I have a Java process running and I terminate the JVM through the Unix console (kill -9 <<process id>> , can I still manage to trigger
some process before the Java application stops?
I would like to trigger the process through Java programmatically.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at Runtime.addShutdownHook(Thread hook). Be sure to read thru the caveats listed in tha API docs. The hook must do its work quickly and be thread-safe and avoid deadlocks.
 
Steven Wong
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Michael
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic