use context class loader

This commit is contained in:
Taro L. Saito 2011-08-01 17:03:55 +09:00
parent 9c86835cc3
commit 3e533b4e7d
1 changed files with 11 additions and 11 deletions

View File

@ -81,13 +81,9 @@ import java.util.Properties;
*/ */
public class SnappyLoader public class SnappyLoader
{ {
private static boolean isInitialized = false; private static boolean isInitialized = false;
private static boolean isLoaded = false; private static boolean isLoaded = false;
private static SnappyNativeAPI api = null; private static SnappyNativeAPI api = null;
// preserved for LocalSnappyNativeLoader
private static HashMap<String, Boolean> loadedLibFiles = new HashMap<String, Boolean>();
private static HashMap<String, Boolean> loadedLib = new HashMap<String, Boolean>();
private static ClassLoader getRootClassLoader() { private static ClassLoader getRootClassLoader() {
ClassLoader cl = SnappyLoader.class.getClassLoader(); ClassLoader cl = SnappyLoader.class.getClassLoader();
@ -193,7 +189,8 @@ public class SnappyLoader
try { try {
if (!useNativeCodeInjection) { if (!useNativeCodeInjection) {
// Use the local loader // Use the local loader
return SnappyLoader.class.getClassLoader().loadClass(LocalSnappyNativeLoader.class.getName()); return Thread.currentThread().getContextClassLoader()
.loadClass(LocalSnappyNativeLoader.class.getName());
} }
else { else {
// Use parent class loader to load SnappyNative, since Tomcat, which uses different class loaders for each webapps, cannot load JNI interface twice // Use parent class loader to load SnappyNative, since Tomcat, which uses different class loaders for each webapps, cannot load JNI interface twice
@ -246,7 +243,7 @@ public class SnappyLoader
private static void loadNativeLibrary(Class< ? > loaderClass) { private static void loadNativeLibrary(Class< ? > loaderClass) {
if (loaderClass == null) if (loaderClass == null)
throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, "missing snappy loader class"); throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, "missing snappy native loader class");
try { try {
File nativeLib = findNativeLibrary(); File nativeLib = findNativeLibrary();
@ -272,9 +269,12 @@ public class SnappyLoader
private static class LocalSnappyNativeLoader private static class LocalSnappyNativeLoader
{ {
// preserved for LocalSnappyNativeLoader
private static HashMap<String, Boolean> loadedLibFiles = new HashMap<String, Boolean>();
private static HashMap<String, Boolean> loadedLib = new HashMap<String, Boolean>();
public static synchronized void load(String lib) { public static synchronized void load(String lib) {
if (loadedLibFiles.containsKey(lib) && loadedLibFiles.get(lib) == true) if (loadedLibFiles.containsKey(lib))
return; return;
try { try {
@ -287,7 +287,7 @@ public class SnappyLoader
} }
public static synchronized void loadLibrary(String libname) { public static synchronized void loadLibrary(String libname) {
if (loadedLib.containsKey(libname) && loadedLib.get(libname) == true) if (loadedLib.containsKey(libname))
return; return;
try { try {