]> source.dussan.org Git - javassist.git/commitdiff
Control ctxClassLoader usage per thread 250/head
authorskybber <lada.dvorak7@gmail.com>
Sun, 17 Mar 2019 08:26:09 +0000 (09:26 +0100)
committerskybber <lada.dvorak7@gmail.com>
Sun, 17 Mar 2019 08:26:09 +0000 (09:26 +0100)
src/main/javassist/runtime/Desc.java

index c733b30d930bbae7e7fb2ed813e37282399bd5bb..9fbe8f22aaee24bae504c20bad7c8712a2d7bf93 100644 (file)
@@ -34,10 +34,25 @@ public class Desc {
      */
     public static boolean useContextClassLoader = false;
 
+    private static final ThreadLocal<Boolean> USE_CONTEXT_CLASS_LOADER_LOCALLY = new ThreadLocal<Boolean>() {
+        @Override
+        protected Boolean initialValue() {
+            return false;
+        }
+    };
+
+    public static void setUseContextClassLoaderLocally() {
+        USE_CONTEXT_CLASS_LOADER_LOCALLY.set(true);
+    }
+
+    public static void resetUseContextClassLoaderLocally() {
+        USE_CONTEXT_CLASS_LOADER_LOCALLY.remove();
+    }
+
     private static Class<?> getClassObject(String name)
         throws ClassNotFoundException
     {
-        if (useContextClassLoader)
+        if (useContextClassLoader || USE_CONTEXT_CLASS_LOADER_LOCALLY.get())
             return Class.forName(name, true, Thread.currentThread().getContextClassLoader());
         return Class.forName(name);
     }