问题
I'm using java.util.prefs
to store application settings and use those settings regularly in the application. Upon application start, should I load those settings into memory so that I'm not constantly retrieving them from the preferences file? I'm asking from the perspective of performance and for standard coding practice. I feel like there's a trade off for performance:
- If you load them into memory you have quicker access to them but then when you change any settings you have to make the changes to both the parameters in your node and in memory.
- If you keep them just in the node, you're constantly doing
myPreferences.get()
.
回答1:
I'm pretty sure that the preferences are cached, so get()
should be fast. You can look at the code for FileSystemPreferences, it just does a few checks and looks up the key in a Map
.
来源:https://stackoverflow.com/questions/11313179/should-i-always-use-the-java-preferences-api-get-method-or-load-them-into-memo