The following code snippet is taken from android JellyBean ReferenceQueue.java in the libcore project.
Can someone tell me why a synchronized block is used, synchronizing on ReferenceQueue.class, instead of adding the synchronized qualifier to the method? Are these two approaches functionally equivalent in this instance?
From similar questions that I looked at it seems to be more efficient to make the method synchronized.
Cheers, Matt
public class ReferenceQueue<T> {
... <snip> ...
public static Reference unenqueued = null;
static void add(Reference<?> list) {
    synchronized (ReferenceQueue.class) {
        if (unenqueued == null) {
            unenqueued = list;
        } else {
            Reference<?> next = unenqueued.pendingNext;
            unenqueued.pendingNext = list.pendingNext;
            list.pendingNext = next;
        }
        ReferenceQueue.class.notifyAll();
    }
}
 
    