Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
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: 5407
    
  13

I have implemented something similar.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Dmitri Cherkas
Ranch Hand

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

Joined: Dec 28, 2007
Posts: 2266
    
    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 !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: (UrlyBird) Managing the stop of application with Runtime.getRuntime().addShutdownHook().