• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Dmitri Cherkas
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9109
75
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have implemented something similar.
 
Dmitri Cherkas
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, i'm happy.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:I have implemented something similar.


Me too! Shutdown hooks rock!
 
Dmitri Cherkas
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for reply, famous Roberto !
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic