Dec 16 2011

Java library performance optimzation using local references to final members: should you use it?

Category: javaUlrich Palha @ 9:37 am

Mysterious java idiom

While I was browsing through the java.util.concurrent source code, I noticed widespread use of the following idiom

    private final ReentrantLock mainLock = new ReentrantLock();
        ...
        //local reference to final member variable
        final ReentrantLock mainLock = this.mainLock; 
        mainLock.lock(); 
        try {
            ...     
        } finally {
            mainLock.unlock();
    }

Given that member mainLock is final, I could not understand the benefit of declaring a local reference. Continue reading “Java library performance optimzation using local references to final members: should you use it?”

Tags: , , ,