What is the best option for reading Java property files?

I have an application that uses a servlet to read an intialization parameter from web.xml to locate a property file. Then serlvet creates an instance of the class that saves the file location for reading other programs as needed. This class has corresponding get and set methods.

But my question is about accessing properties: should a physical property file be read by each program as at run time or if the properties will be stored in memory instead?

Currently, properties do not change at runtime, but can this change? I have seen various alternative approaches, but not sure which is better.

thanks

Mr. Morgan

+4
source share
2 answers

If the properties file is small, storing it in memory may be more efficient than reading it from disk every time. You may consider Apache Commons Configuration . It supports auto reboot .

+6
source

Want server values ​​from a .properties file? First load the properties from the file and cache them. And, if necessary, the server from the cache. Ask the file-watching dog that controls the file, say every x sec and reloads the properties from the file when the file changes.

+1
source

Source: https://habr.com/ru/post/1312005/


All Articles