Class ThreadLocalSystemProperties

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,​java.lang.Object>

    public class ThreadLocalSystemProperties
    extends java.util.Properties
    Support for storing System.setProperty calls in thread local. Mainly used to deal with third party libraries which sets new system properties and never clear them.

    To Enable usage of this class a single call to enable() has to be done. To Disable usage of this class, a call to disable() need to be made. This needs to be done to remove all references for this class's classloader for smooth class unloading.

    Calling record() before any such operation will store all calls to System.setProperty(String, String) in the current thread local only. Even for properties which are already defined in global level a new property is created in thread local Also calls to System.getProperty(String) will return values from current thread local and falls back to global vm level properties if not present in thread local.

    Calling stop() will stop storing in thread local and any call to System.setProperty(String, String) will be store in global vm level properties for the current thread.

    See Also:
    Serialized Form
    • Field Summary

      • Fields inherited from class java.util.Properties

        defaults
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void disable()
      Will only disable ThreadLocalProperties at the vm level Vm level properties previously set will still be present
      ThreadLocalSystemProperties enable()
      Will set ThreadLocalProperties as the default System properties at the vm level Existing System properties are still available by default at global level across all threads
      java.util.Set<java.util.Map.Entry<java.lang.Object,​java.lang.Object>> entrySet()  
      static void executeInThreadLocalSystemProperties​(java.lang.Runnable runnable)  
      java.lang.String getProperty​(java.lang.String key)  
      java.lang.String getProperty​(java.lang.String key, java.lang.String defaultValue)  
      java.util.Set<java.lang.Object> keySet()  
      void list​(java.io.PrintStream out)  
      void list​(java.io.PrintWriter out)  
      java.util.Enumeration<?> propertyNames()  
      java.lang.Object setProperty​(java.lang.String key, java.lang.String value)  
      int size()  
      java.util.Set<java.lang.String> stringPropertyNames()  
      java.util.Set<java.lang.Object> values()  
      • Methods inherited from class java.util.Properties

        clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, equals, forEach, get, getOrDefault, hashCode, isEmpty, keys, load, load, loadFromXML, merge, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, store, store, storeToXML, storeToXML, storeToXML, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • enable

        public ThreadLocalSystemProperties enable()
        Will set ThreadLocalProperties as the default System properties at the vm level Existing System properties are still available by default at global level across all threads
      • disable

        public void disable()
        Will only disable ThreadLocalProperties at the vm level Vm level properties previously set will still be present
      • executeInThreadLocalSystemProperties

        public static void executeInThreadLocalSystemProperties​(java.lang.Runnable runnable)
      • getProperty

        public java.lang.String getProperty​(java.lang.String key)
        Overrides:
        getProperty in class java.util.Properties
      • getProperty

        public java.lang.String getProperty​(java.lang.String key,
                                            java.lang.String defaultValue)
        Overrides:
        getProperty in class java.util.Properties
      • setProperty

        public java.lang.Object setProperty​(java.lang.String key,
                                            java.lang.String value)
        Overrides:
        setProperty in class java.util.Properties
      • propertyNames

        public java.util.Enumeration<?> propertyNames()
        Overrides:
        propertyNames in class java.util.Properties
      • stringPropertyNames

        public java.util.Set<java.lang.String> stringPropertyNames()
        Overrides:
        stringPropertyNames in class java.util.Properties
      • list

        public void list​(java.io.PrintStream out)
        Overrides:
        list in class java.util.Properties
      • list

        public void list​(java.io.PrintWriter out)
        Overrides:
        list in class java.util.Properties
      • keySet

        public java.util.Set<java.lang.Object> keySet()
        Specified by:
        keySet in interface java.util.Map<java.lang.Object,​java.lang.Object>
        Overrides:
        keySet in class java.util.Properties
      • values

        public java.util.Set<java.lang.Object> values()
        Specified by:
        values in interface java.util.Map<java.lang.Object,​java.lang.Object>
        Overrides:
        values in class java.util.Properties
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<java.lang.Object,​java.lang.Object>
        Overrides:
        size in class java.util.Properties
      • entrySet

        public java.util.Set<java.util.Map.Entry<java.lang.Object,​java.lang.Object>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<java.lang.Object,​java.lang.Object>
        Overrides:
        entrySet in class java.util.Properties