同步(this)和synced(ClassName.class)有什么区别?
2022-09-02 23:14:37
我读到过一些出于各种原因应该避免的地方。然而,我遇到的一些值得尊敬的代码在构造函数中使用了以下内容:synchronized(this)
public SomeClass(Context context) {
if (double_checked_lock == null) {
synchronized (SomeClass.class) {
if (double_checked_lock == null) {
// some code here
}
}
}
}
和 之间真的有区别吗?synchronized(this)
synchronized(SomeClass.class)