RFR [9] 8056152 API to create Threads that do not inherit InheritableThreadLocals

Chris Hegarty chris.hegarty at oracle.com
Wed Dec 9 21:05:00 UTC 2015


On 8 Dec 2015, at 14:49, David M. Lloyd <david.lloyd at redhat.com> wrote:

> Great! Now all we need is a way to tell threads to remove all thread locals on exit, and the scourge of ITL might be somewhat mitigated. :-)

David,

The fields of Thread that hold references to TLs and ITLs are cleared at exit,
as seen from the snippet below. Or have I missed your point?

public class Thread {
  ..
  private void exit() {
      if (group != null) {
          group.threadTerminated(this);
          group = null;
      }
      /* Aggressively null out all reference fields: see bug 4006245 */
      target = null;
      /* Speed the release of some of these resources */
      threadLocals = null;
      inheritableThreadLocals = null;
      inheritedAccessControlContext = null;
      blocker = null;
      uncaughtExceptionHandler = null;
  }
}

-Chris.

> On 12/08/2015 08:15 AM, Chris Hegarty wrote:
>> Many threads created by the platform are short lived and perform some
>> simple async operation on behalf of the platform. These threads typically
>> use/extend sun.misc.ManagedLocalsThread. This is a convenient internal
>> API that can be used to create threads that do not wish to inherit initial
>> values from inheritable thread-local variables.
>> 
>> I'd like to propose an additional java.lang.Thread constructor that exposes
>> the ability to explicitly "opt out" of inheriting these initial values ( from
>> inheritable thread-local variables ). This seems like useful general
>> functionality, given the amount of usage in the JDK of the internal API.
>> 
>> This new public API can then be used to replace usages of the internal
>> sun.misc.ManagedLocalsThread. As part of this bug I've only retrofitted
>> the usage in the sources of the base module. Other modules can be done
>> as a follow up.
>> 
>> Webrev:
>>   http://cr.openjdk.java.net/~chegar/8056152/00/webrev/
>> 
>> -Chris.
>> 
>> [1] https://bugs.openjdk.java.net/browse/JDK-8056152
>> 
> 
> -- 
> - DML




More information about the core-libs-dev mailing list