Thread 2 then executes and assigns instance to inst at //2.
然后执行线程 2 并在 //2 处将 instance 赋值给 inst。
Another idea is to use the keyword volatile for the variables inst and instance.
另一个想法是针对变量inst以及instance使用关键字volatile。
It tries to do this by introducing the local variable inst and a second synchronized block. The theory works as follows.
它试图通过引入局部变量inst和第二个synchronized块来解决这一问题。
应用推荐