File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 Murach's Java Servlets and JSP this week in the Servlets 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: 5126
    
  12

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: 2258
    
    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 !
 
 
subject: (UrlyBird) Managing the stop of application with Runtime.getRuntime().addShutdownHook().
 
Similar Threads
shutting down virtual marchine and Shutdown Hooks
Allow the user to change data file when running app in client mode?
The mode flag
Database location
server/alone command line