| Author |
(UrlyBird) Managing the stop of application with Runtime.getRuntime().addShutdownHook().
|
Dmitri Cherkas
Ranch Hand
Joined: Mar 22, 2010
Posts: 37
|
|
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: 3820
|
|
|
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: 37
|
|
Ok, i'm happy.
|
 |
Roberto Perillo
Bartender
Joined: Dec 28, 2007
Posts: 2147
|
|
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: 37
|
|
Thank you for reply, famous Roberto !
|
 |
 |
|
|
subject: (UrlyBird) Managing the stop of application with Runtime.getRuntime().addShutdownHook().
|
|
|