chenzhiguo on Nostr: ...
不,因为判断是在synchronized之前完成的,所以多个线程阻塞在synchronized上等待挨个执行时,后面的代码还是会被执行,singleton2会被多次赋值,所以它不是线程安全的单例对象。
Published at
2023-02-08 10:38:18Event JSON
{
"id": "881af7a79c9d775ab2b0a8eb30e52ef6604067b35d3ee151bdfdb07d294d25e1",
"pubkey": "aae9cfdb3113db442c1ad8d4c670a28091e5267748e71d2c1e189e423dbea1bf",
"created_at": 1675852698,
"kind": 1,
"tags": [
[
"e",
"02384d7b2cb74c728c4ee3cda470f1163b6e1feb37e9721cd42b5beb4b575c7e",
""
],
[
"e",
"e4e8a4f07d0d164ab993fd03f75ac284bed38e6adbf2f4176a548631b72e8c80"
],
[
"p",
"5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2"
]
],
"content": "不,因为判断是在synchronized之前完成的,所以多个线程阻塞在synchronized上等待挨个执行时,后面的代码还是会被执行,singleton2会被多次赋值,所以它不是线程安全的单例对象。",
"sig": "11eca7f38cd1d6c63a1c6f4cb230836783c264b2d00020bd3f150b327e67e0b5561a17bed12041de187e315f731987ddaabdaefd16860dfd7ea8f268630054dc"
}