这是我当前的代码。我想知道如果已经同步,我是否需要包装isObjectActive()在同步块中?getState()
private final Object lock = new Object();
@GuardedBy("lock")
private EventTypes state;
@GuardedBy("lock")
public void setState(final EventTypes state) {
synchronized (lock) {
this.state = state;
}
}
@GuardedBy("lock")
@VisibleForTesting
public EventTypes getState() {
synchronized (lock) {
return state;
}
}
@GuardedBy("lock")
public boolean isObjectActive() {
synchronized (lock) {
return getState() == EventTypes.ACTIVE;
}
}
慕工程0101907
相关分类