Coming from the question will two strings with same content be stored in the same memory location?
Having the Java code
String s1="Java";
will this string be allocated in the same memory location (or multipe):
- if to launch the same program multiple times executing it in parallel (concurrently)?
Possible answer:
I am currently C# developer (though programmed in Java in the previous millennium).
I asked this question because I believed it is the same between .NET CLR and Java (JVM) and I was hoping to get the answer for .NET apps (but somehow was in doubt by frequently encountered "application" pool terms).
So, it seems to be (sorry for not exhaustively searching before asking):
with the answer that string intern pool is shared per all instances/programs of the same JVM or .NET CLR.
@gennady-vanin-novosibirsk....
String s1="Java";String s2="Java";String s3="Java";String s4="Java";
- The above all objects available in StringConstantPool location those are all objects are pointing to only one ("Java") location
Is string pool created per class basis or per JVM basis?
There is one String pool per JVM ... unless you are using some exotic JVM where they've decided to implement it differently.
I think that answers it, right?
from similar question
Same memory location:
String s1="Hola";
String s2="Hola";
Distinct memory location:
String s1="Hola";
String s2=new String("Hola");
Strings of same contents will share same space for every instance of same JVM
来源:https://stackoverflow.com/questions/15827344/when-do-not-two-strings-with-same-content-share-the-same-memory