从类文件访问属性文件或静态常量更快吗?

发布于 2024-08-30 06:57:07 字数 84 浏览 4 评论 0原文

我在 tomcat 容器中开发一个 Web 服务应用程序,该 Web 应用程序有很多属性,例如常量、错误消息等。

有什么更好更快的方法呢?

I develop a webservice application in a tomcat container, I have a lot of properties for the webapp like constants, error messages and so on.

What is the better and faster way to?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

云之铃。 2024-09-06 06:57:07

一如既往,答案是分析它

一般来说,这种微观优化几乎肯定无关紧要。不过,请随意分析一下它并看看。

The answer, as always, is profile it.

In general, this is the sort of micro-optimization that almost certainly won't matter. Feel free to profile it and see, though.

兮子 2024-09-06 06:57:07

一般为静态常量; IO 活动总是会变慢。

但是,硬编码值意味着如果必须更改该值,则需要重新编译应用程序。作为开发人员,您可以决定是否需要在软件发布之外更改这些值。

Generally static constants; IO activity will always be slower.

However, hard-coding values means that the app will need to be recompiled if the value has to change. It's your call as a developer as to whether the values will ever need to be changed outside of a software release.

薄暮涼年 2024-09-06 06:57:07

作为Bozho 说,就原始速度而言,你将很难击败公共静态决赛。但速度并不是一切。例如,如果您需要担心本地化问题,那么属性文件可能会更好,尽管您可能想查看 ResourceBundle 代替。

As Bozho says, in terms of raw speed, you're going to have trouble beating a public static final. But speed isn't everything. If you need to worry about localization at all, for instance, a properties file would probably be better, although you might want to look at a ResourceBundle instead.

生生不灭 2024-09-06 06:57:07

public static final String SOME_CONSTANT = "contstantValue";

这使得编译器内联该值,因此在运行时不会发生任何事情。

您还可以将值存储在任何位置(.properties 文件)并将它们加载到静态初始化块中。

public static final String SOME_CONSTANT = "contstantValue";

This makes the compiler inline the value, so you have nothing happening at runtime.

You can also store the values anywhere (.properties file) and load them in a static initializer block.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文