chenzhiguo on Nostr: 那这一段线程安全吗?class Singleton2{ private static volatile Singleton2 ...
那这一段线程安全吗?class Singleton2{ private static volatile Singleton2 singleton2; private Singleton2()); public static Singleton2 getInstance(){ if(singleton2 != null){ return singleton2; } synchronized (Singleton2.class){ singleton2 = new Singleton2(); } return singleton2;}}
Published at
2023-02-08 08:47:55Event JSON
{
"id": "957ca4fbbb37643286d5f748614bfc02ac06a04a3013f2cbae20832006e487c4",
"pubkey": "aae9cfdb3113db442c1ad8d4c670a28091e5267748e71d2c1e189e423dbea1bf",
"created_at": 1675846075,
"kind": 1,
"tags": [
[
"e",
"02384d7b2cb74c728c4ee3cda470f1163b6e1feb37e9721cd42b5beb4b575c7e",
""
],
[
"e",
"8d9dffc1b721a1b4dcc0d9b91c2efc005adc83c5bc6fcebfbb2b4fe9ebc3d180"
],
[
"p",
"5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2"
]
],
"content": "那这一段线程安全吗?class Singleton2{ private static volatile Singleton2 singleton2; private Singleton2()); public static Singleton2 getInstance(){ if(singleton2 != null){ return singleton2; } synchronized (Singleton2.class){ singleton2 = new Singleton2(); } return singleton2;}}",
"sig": "fadd662190952cce463a8802450559af5491423fc96388350e6d684e6b2bdb2be2a1bd49be9bb83dc657ed5a0583910909a6dc8c180196fc8df1ff25eb4efc6d"
}