Optimize resource listener. 

Take into account final classes and the fact that classes are singletons inside a JVM. 
See http://stackoverflow.com/q/7322469/693752