I write some code like this:
public static void function7() {
String str = "123";
String str2 = "123";
synchronized (str) {
if(str != null) {
str2 = "123";
}else{
str = "456";
}
System.out.println(str2);
}
}
The code compile well. But a plugin of Eclipse, Find bugs, give the follow error report:
Constant Strings are interned and shared across all other classes loaded by the JVM. Thus, this could is locking on something that other code might also be locking. This could result in very strange and hard to diagnose blocking and deadlock behavior.
What exactly it means?