Java Scoped Values: Better ThreadLocals
Largely motivated by Virtual Threads, a new lightweight thread-local alternative has been introduced with the incubation JEP-429 called ScopedValues. ScopedValue
is purpose-built to provide a lighter-weight alternative to ThreadLocal
that works well with virtual threads and also solves multiple API shortcomings of the twenty-five year old counterpart. This article will dive in to how ScopedValue
is different, and how it is made faster under the covers.