Should I always use the java preferences API get() method or load them into memory and get them from there?

天涯浪子 提交于 2021-02-08 19:39:03

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!