Created
June 14, 2011 04:13
-
-
Save utsengar/1024302 to your computer and use it in GitHub Desktop.
fix singelton issues when using multiple classloaders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Class getClass(String classname) throws ClassNotFoundException { | |
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | |
if(classLoader == null) | |
classLoader = Singleton.class.getClassLoader(); | |
return (classLoader.loadClass(classname)); | |
} | |
} | |
//Source: http://snehaprashant.blogspot.com/2009/01/singleton-pattern-in-java.html | |
/** The preceding method tries to associate the classloader with the current thread; if that | |
classloader is null, the method uses the same classloader that loaded a singleton base class. The | |
preceding method can be used instead of Class.forName(). **/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment