RFR [9] 8056152 API to create Threads that do not inherit InheritableThreadLocals
Moritz Bechler
bechler at agno3.eu
Tue Dec 8 23:15:24 UTC 2015
Hi,
> 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.
>
I can only very much second that request as I recently came across a
library using lazy initialized thread pools in a very bad way. This
usage currently unconditionally leaks the caller context and there is no
good way (without knowing the internals and using reflection) to prevent
that.
As for the interface I would also prefer a more versatile approach as
this could be further extended to specifying whether TCCL should be
inherited and which ACC should be used (ok, that latter one is a bit
tricky, but I'd guess an explicit API would make people more aware of
the issue).
Moritz
--
AgNO3 GmbH & Co. KG, Sitz Tübingen, Amtsgericht Stuttgart HRA 728731
Persönlich haftend:
Metagesellschaft mbH, Sitz Tübingen, Amtsgericht Stuttgart HRB 744820,
Vertreten durch Joachim Keltsch
More information about the core-libs-dev
mailing list