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 ]
Sun Certified Developer for the Java 2 Platform
Sun Certified Enterprise Architect for the Java Platform, Enterprise Edition 5
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.