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

from java.util.concurrent.ThreadPoolExecutor
1
2
3
4
5
6
7
8
9
10
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: , , ,


Dec 09 2011

HTML Parsers and other libraries: don’t write your own till you know, and have tested, what already exists

Category: java,open sourceUlrich Palha @ 3:53 pm

It seemed simple…

I needed to extract some HTML content for one of the projects I was working on. It seemed easy enough to retrieve the content and parse out the title tag, so I quickly threw together the following code to retrieve the title tag. Continue reading “HTML Parsers and other libraries: don’t write your own till you know, and have tested, what already exists”

 

 

Tags: , , ,