Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6493635

(cl) ClassLoader-local variables similar to ThreadLocal

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P5 P5
    • None
    • 6
    • core-libs

      A DESCRIPTION OF THE REQUEST :
      Often it is useful to associate state with a ClassLoader. For example, references to Class, Field, Method and Constructor should have the same lifetime as the ClassLoader. Currently reloading ClassLoaders either leaks or complicated weak/soft reference mechanisms cause unnecessary work.

      I propose an easy to implement class along the lines of ThreadLocal:

      package java.lang;
      public class ClassLoaderLocal<T> {
          protected T initialValue(ClassLoader loader) { ... }
          public T get(ClassLoader loader) { ... }
          public void set(ClassLoader loader, T value) { ... }
          public void remove(ClassLoader loader) { ... }
          public void removeAll() { ... }
      }

      JUSTIFICATION :
      java.sql.DriverManager leaks. As does java.beans and java.util.logging.Level. Even without reloading ClassLoaders, the soft cache in serialisation can cause disruption of the permanent generation. With reloading, it maintains soft reachability to ClassLoaders. The problem also applies to any third-party software with similar functionality.


      CUSTOMER SUBMITTED WORKAROUND :
       o Leak and be damned (the common solution).
       o Use a complicated soft reference solution, potentially hurting performance and causing soft leaks (as serialization).
       o Subclass the interesting ClassLoaders (as AppletClassLoader does for AppContext).
       o Insert a class into the ClassLoader context holding the relevant objects.

            Unassigned Unassigned
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: