<分区>
我写了一些这样的代码:
public static void function7() {
String str = "123";
String str2 = "123";
synchronized (str) {
if(str != null) {
str2 = "123";
}else{
str = "456";
}
System.out.println(str2);
}
}
代码编译良好。 但是Eclipse的一个插件,Find bugs,报错如下:
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.
具体是什么意思?