@GuardedBy annotation with java.util.concurrent.locks.ReadWriteLock

At the time of this writing, @GuardedBy isn’t fully implemented by Findbugs, and is mostly just for documentation. (It is partially implemented.)

I always use @GuardedBy("readwritelock") or the object that I use to synchronize.

For example of the latter:

class Example {
    private Object lock = new Object();

    @GuardedBy("lock")
    private Stuff innards = ...;

    public void work() {
        synchronized(lock) {
            workWith(innards.goop());
        }
    }        
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)