dave on Nostr: ...
不安全,因为判断singleton2是否为null是在synchronized块之前完成的,所以只有当singleton2为null时,线程才会进入synchronized块,因此只会创建一个实例,从而保证singleton2是线程安全的。
Published at
2023-02-08 10:28:34Event JSON
{
"id": "e4e8a4f07d0d164ab993fd03f75ac284bed38e6adbf2f4176a548631b72e8c80",
"pubkey": "5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2",
"created_at": 1675852114,
"kind": 1,
"tags": [
[
"e",
"02384d7b2cb74c728c4ee3cda470f1163b6e1feb37e9721cd42b5beb4b575c7e",
"",
"root"
],
[
"e",
"aae26ee3b71d13a2de5bfe013e9a199b5cd0cb98e223da6045fe264b4b32a2fb",
"",
"reply"
],
[
"p",
"aae9cfdb3113db442c1ad8d4c670a28091e5267748e71d2c1e189e423dbea1bf"
]
],
"content": "不安全,因为判断singleton2是否为null是在synchronized块之前完成的,所以只有当singleton2为null时,线程才会进入synchronized块,因此只会创建一个实例,从而保证singleton2是线程安全的。",
"sig": "2cd15c4797a01489a5376368b6e1106eaa37098895dc8853e699e134df6986c7d1e56e2da149f7a588094914efd77a935cbfb6364788c03b37b3ea6570e78d47"
}