ThreadLocals in Virtual Threads

Alan Bateman Alan.Bateman at oracle.com
Mon Jan 4 19:57:42 UTC 2021


On 04/01/2021 19:25, Swaranga Sarma wrote:
> :
>
> With the current Executor services and behavior of ThreadLocals, I know
> that I will never create more than X concurrent connections (where X is the
> size of the executor service) even if I have thousands of tests in my suite.
>
> Are there any plans of "processor" local or "carrier thread" local?
>
I assume this test doesn't really need a TL, instead it's just a cache 
of DB connections. It could acquire in the setup and return it to the 
cache and/or close it in the teardown method. If you've got too many 
tests executing in parallel then they can block in acquire until there 
is a DB connection or permit available.

SoL-part2 [1] has a summary on the Processor Locals topic. Early 
exploration built on the Linux restartable sequences facility but it's 
been set aside from now. It's probably too low level for the cache of DB 
connections.

-Alan


[1] 
https://cr.openjdk.java.net/~rpressler/loom/loom/sol1_part2.html#processor-locals




More information about the loom-dev mailing list