In java's documentation it says that in the below example, the condition will be true:
String a = new String("ABC");
String b = new String("ABC");
if (a.intern() == b.intern())
{
....
}
I wanted to know, if that is still true when considering that a
and b
are defined in different Threads
, or even different ClassLoaders
?
This question rose when I needed an ability to synchronize a block that loads a certain configuration based on an entity's name, so I wanted to do something like:
synchronized (entityName.intern())
{
}
I'm not sure this is a good practice, so I'm probably not going to pursue this direction - but the question still interests me.
String
twice using two different class loaders? – Allstar