aspose file tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes (UrlyBird) Managing the stop of application with Runtime.getRuntime().addShutdownHook(). Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "(UrlyBird) Managing the stop of application with Runtime.getRuntime().addShutdownHook()." Watch "(UrlyBird) Managing the stop of application with Runtime.getRuntime().addShutdownHook()." New topic
Author

(UrlyBird) Managing the stop of application with Runtime.getRuntime().addShutdownHook().

Dmitri Cherkas
Ranch Hand

Joined: Mar 22, 2010
Posts: 40
This is mine application logic against reading-writing data from/to database file :

1) application reads data in memory (HashMap) from database file only when :
1_1) button "Execute" is pressed after user set dblocation and serverportnumber on the GUI in "server" mode
1_2) the application is started in "alone" mode;

when the application starts in "server" or "alone" modes (see "1_1" and "1_2" above) i set up a class for managing secure exit as follows : Runtime.getRuntime().addShutdownHook(SecureExit());

2) the application writes data from memory (HashMap) to database file only in one point - in the class "SecureExit()" (see above) and "SecureExit()" is not called in my code explicitly (i.e. SecureExit() is activated only by JVM).

is it the right design decision ?
Thank you.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5844
    
  17

I have implemented something similar.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
OCAJP 7
Dmitri Cherkas
Ranch Hand

Joined: Mar 22, 2010
Posts: 40
Ok, i'm happy.
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2268
    
    3

Roel De Nijs wrote:I have implemented something similar.


Me too! Shutdown hooks rock!


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Dmitri Cherkas
Ranch Hand

Joined: Mar 22, 2010
Posts: 40
Thank you for reply, famous Roberto !
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: (UrlyBird) Managing the stop of application with Runtime.getRuntime().addShutdownHook().