我们可以避免java中字符串的实习吗?
我们可以完全禁用字符串的实习吗?这可能不是真正有帮助,只是一个想法。我认为至少有一点是有帮助的,即在 jvm 调整期间,控制 perm gen 的大小。
例如,如果我给出一个 OSGI 框架,任何人都可以添加任意数量的自己的捆绑包,并且每个捆绑包字符串实习可能会完全搞砸我的调整参数。 (当然我知道我们应该对给定的固定发行版进行调整,但仍然......)
任何想法!
Can we completely disable interning of strings. It might not be really helpful, but just a thought. I can think atleast one point where it could be helpful i.e. during jvm tuning, controlling the size of the perm gen.
For e.g. if I give out an OSGI framework and anyone can add any number of bundles of their own and each bundles string interning can completely screw up my tuning parameters. (Ofcourse I know that we should do tuning on a given fixed distro, but still...)
Any thoughts!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Permgen 大小/使用对于现代 JVM 来说不是问题。当没有剩余的引用时,内部字符串可供垃圾收集器使用。
(不,你不能“关闭”字符串文字的驻留)。
Permgen size/usage isn't an issue with modern JVMs. Interned strings are made available to the garbage collector when there are no remaining references to them.
(And no, you can't "turn off" interning of string literals).
您可以通过在代码中不使用任何字符串文字来禁用大多数字符串的驻留。您可以使用 char[] 代替并从中构建字符串。例如,
正如您所提到的,这只会给自己增加工作量,而且只会让事情变得更糟。
如果他们添加捆绑包,他们可能需要更高的最大内存、永久代大小、直接内存大小、不同的 NewSize 比率、甚至不同的 GC。防止这种情况的唯一方法是防止 OSGi 容器中的任何其他模块。
或者您可以只是说,如果添加捆绑包,您可能需要更改调整参数。
You can disable the interning of most string, by not using any String literals in your code. You could use char[] instead and build Strings from those. E.g.
As you mentioned, this just creates work for yourself and will just make things worse.
If they add bundles, they could need a higher, maximum memory, perm gen size, direct memory size, different NewSize ratio, even a different GC. The only way to prevent this, is to prevent any other modules in your OSGi container.
Or you can just say, if you add bundles you may need to change the tuning paramters.
从 Oracle 的 Java 7 开始,实习生字符串池不再存储在 PerGen 中。在此处阅读更多信息 http://java-performance.info/string -intern-in-java-6-7-8/
Since Oracle's Java 7 the intern string pool isn't stored in PerGen anymore. Read more here http://java-performance.info/string-intern-in-java-6-7-8/
String 是一个最终类,并且不能延长。因此,不可以——你不能删除 Java 中实习字符串的能力。
String is a final class, and cannot be extended. Therefore, no - you cannot remove the ability to intern Strings in Java.