gpt4 book ai didi

Java:在 String 对象上同步

转载 作者:搜寻专家 更新时间:2023-10-31 20:01:37 25 4
gpt4 key购买 nike

<分区>

我写了一些这样的代码:

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.

具体是什么意思?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com