How do I create a real virtual thread pool?
Alan Bateman
alan.bateman at oracle.com
Fri Sep 26 10:42:20 UTC 2025
On 26/09/2025 10:36, Jianbin Chen wrote:
> Hi everyone,
>
> I hope you’re doing well. I have a question about a multi-tenant
> scenario. I want to create a dedicated thread pool for each tenant,
> and these pools will perform a lot of I/O (for example, database reads
> and writes). For this reason I’d like to use virtual threads. However,
> because virtual threads share platform threads under the hood, they
> cannot be fully isolated from one another.
>
Can you say a bit more about the multi-tenancy implementation? Is this a
fork of the JDK with deep changes to isolate tenants, or is this
isolation built with module layers or class loaders? If the latter then
I assume it's an issue for the FJP common pool and all other system-wide
resources.
So while the JDK doesn't have any support for tenancies, there is
prototype/experimental support for custom schedulers in the loom repo
[1]. That could be used to experiment with a having a virtual thread
scheduler per tenant, or using a system-wide scheduler that dispatches
the tasks for virtual threads in a tenant to the carriers in that
tenant. It could be fun to work on. If you do explore this area then
please come back with any results.
-Alan
[1]
https://github.com/openjdk/loom/blob/fibers/loom-docs/CustomSchedulers.md
More information about the loom-dev
mailing list