This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Saving properties in shutdownhook

 
Ronald Wouters
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

do you think if a Runtime shutdownhook is a good place to save/store the suncerity.properties file ?

Regards,
Ronald Wouters
 
Eiji Seki
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think finalize methods or shutdown hooks are something always to avoid, if possible. =D You cannot be sure that they will execute, right?
What about saving it everytime configuration changes?
 
Alan Mc Kernan
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats was my plan of attack.

The config file is onnly going to be touched once right, on load up ?

So save it then, and continue
 
Aruneesh Salhotra
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One should have the ability of change the configs anytime. Just have a menuBar and when you have any event related to config file, save it.

Ofcouse for application finalize method, you should do clean up of things.
 
Ronald Wouters
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever an event occurs that requires updating the configuration a planned to simple update the given property in the java.util.Properties instance.
The actual writing out the Properties instance to disk, as the suncertify.properties file, is something I planned to do in a shutdown hook.
Indeed most configuration properties for URLyBird are not changed "on the fly" and writing it out to disk whenever a property changes seems a bit overkill.
Anyway, most applications I know only "persist" new configuration changes when they exit normally. If an application crashes, and you start it up again, the old configuration is usually still active. According to the API docs for the addShutdownHook method, the thread that acts as the hook always gets started when the application exits normally. That was my reason for asking about the shutdown hook in the first place.

Alan, you made a good point about the properties being touched once. That is certainly the case for URLyBird. However, most other applications allow you to change options as often as you want, usually using an Edit Options menu item or something similar. Would you also write out the properties to disk in such a case.

Does this all make sense or am I just loosing it ? I need to get some sleep ...

Regards,
Ronald Wouters
[ February 17, 2006: Message edited by: Ronald Wouters ]
 
Eiji Seki
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it depends on the kind of configuration we are talking about.
In case of an Options windows, I see no problem in persisting it when the confirmation button is pressed. The cost of it is not relevant since we are not writing it often and it is not a big file (right? ).

Other properties that may be persisted like search history, window positions and anything else outside of the options window should be persisted when shutting down. The hook you mentioned looks like a nice way of doing it.
 
Aruneesh Salhotra
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do u think storing the search history (even though) not in specs might score points.
 
Ronald Wouters
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My instructions say
You will not receive extra credit points for work beyond the requirements of the specification.


So I am not planning on saving search history.
Extra work but no extra credit ... waste of time and effort.

Regards,
Ronald Wouters
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic