YGC time increasing suddenly
Bernd Eckenfels
bernd-2013 at eckenfels.net
Sat Dec 21 11:45:46 PST 2013
Am 21.12.2013, 17:15 Uhr, schrieb Luciano Molinari <lucmolinari at gmail.com>:
> I noticed that many Strings in the heap are equals..shouldn't JVM keep
> only different Strings and re-use the equals?
When a string is interned (all constants in your classes are interned)
then there is only one instance for a string. However if you (or a
library) construct a new string from bytes/characters then it will not be
automatically interned and therefore created with multiple instances
(basically if you use "new String" you get what you ask for :)
You can use .intern() on a String to get its unique instance, but be sure
to do this only for the most common/often used strings. This does
essentially a hash lookup, so it is most often not a good idea to do it
(unless you know you keep them around for long and/or equal() them very
often. (For example it sometimes make sense to intern() all element names
of Dom Trees but not the (too many different) values).
Gruss
Bernd
--
http://bernd.eckenfels.net
More information about the hotspot-gc-use
mailing list