static 필드인 인스턴스 필드 또는 메서드의 @GuardedBy 어노테이션을 보고합니다. static이 아닌 인스턴스 필드 또는 메서드의 가드가 static인 경우 과도한 잠금 경합을 초래할 수 있습니다. 객체 인스턴스의 각 잠긴 필드에 액세스하면 모든 객체 인스턴스의 해당 필드에 대한 동시 액세스가 차단되기 때문입니다.
예:
private static ReadWriteLock lock = new ReentrantReadWriteLock(); //static guarding field
private Object state;
@GuardedBy("lock")
public void bar() {
state = new Object();
}
지원되는 @GuardedBy 어노테이션:
net.jcip.annotations.GuardedByjavax.annotation.concurrent.GuardedByorg.apache.http.annotation.GuardedBycom.android.annotations.concurrency.GuardedByandroidx.annotation.GuardedBycom.google.errorprone.annotations.concurrent.GuardedBy