New Early Access builds
Alan Bateman
Alan.Bateman at oracle.com
Sat Jan 16 17:22:24 UTC 2021
On 16/01/2021 16:08, Cay Horstmann wrote:
> Build 16-loom+9-316 had Scoped and LightweightThreadLocal classes,
> which are not present in 17-loom+2-42.
> Thread.Builder.disallowThreadLocals is also gone. What's the latest
> thinking on thread locals and scoped variables?
The "thinking" hasn't changed. All threads support thread locals by
default. Thread.Builder has a "noThreadLocals" method that prevents a
thread from setting values for its copy of thread locals (it only sees
the initial value). The builder API also has a method to opt-out of
inheriting the initial value of Inhertiable-TLs, similar to the boolean
parameter on the pre-existing 5-arg Thread constructor.
TLs are problematic for a number reasons, one being that they are too
general with resulting over use. The exploratory into scope variables is
to find a better and more performant solution for the "implicit
parameter" use-case. Also the inheritance case where context or some
immutable object is inherited into a tree of threads or parallel stream
without copying values into the Thread or FJ tasks. Andrew Haley has
been working on this topic and has a new prototype that we expect will
go into the loom repo at some point. That will be the replacement for
the early prototype that was Lightweight-TL.
So yes, there will be a bit of churn and API shimmer but the general
direction, to find better alternatives for some TLs usages, continues.
-Alan
More information about the loom-dev
mailing list