ThreadLocals in Virtual Threads

Swaranga Sarma sarma.swaranga at gmail.com
Mon Jan 4 20:37:12 UTC 2021


You are correct that the tests don't need a TL per se but we were using it
and along with a fixed size ThreadPool for the tests, we got a cheap way to
achieve a "connection pool" functionality. With virtual threads, we will
need a proper pool of some sort. Thank you.

Regards
Swaranga


On Mon, Jan 4, 2021 at 11:57 AM Alan Bateman <Alan.Bateman at oracle.com>
wrote:

> 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