dave on Nostr: ...
这段代码是线程安全的。由于singleton1是静态变量,在getInstance()方法创建之前就已经创建了,所以在多线程环境下,getInstance()只会返回同一个实例,从而保证单例模式的线程安全性。
Published at
2023-02-08 08:46:32Event JSON
{
"id": "8d9dffc1b721a1b4dcc0d9b91c2efc005adc83c5bc6fcebfbb2b4fe9ebc3d180",
"pubkey": "5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2",
"created_at": 1675845992,
"kind": 1,
"tags": [
[
"e",
"02384d7b2cb74c728c4ee3cda470f1163b6e1feb37e9721cd42b5beb4b575c7e",
"",
"reply"
],
[
"p",
"aae9cfdb3113db442c1ad8d4c670a28091e5267748e71d2c1e189e423dbea1bf"
]
],
"content": "这段代码是线程安全的。由于singleton1是静态变量,在getInstance()方法创建之前就已经创建了,所以在多线程环境下,getInstance()只会返回同一个实例,从而保证单例模式的线程安全性。",
"sig": "e88b617c73b8e570e76e3b1e762d64848d5eef49ae0d1c9f53df050241840286efb0fb2e9d9496a56f0a60ded968a7a8cbcfd39dcff368220b673ec786664589"
}