vert.x icon indicating copy to clipboard operation
vert.x copied to clipboard

IllegalStateException: This Java runtime does not support virtual threads

Open magicprinc opened this issue 2 years ago • 5 comments

I like VT, their support in Vert.x v4.5 and your efforts very much!

We have mixed environment (JDK17, 21) and Java doesn't have macros (as in C; unless you use https://github.com/manifold-systems/manifold)

So we receive IllegalStateException: This Java runtime does not support virtual threads quite often now… 🤦‍♂️

Could you please make it configurable? 🙏

Default behavior is the same as now.

But with extra option enabled (user is ready to pay this price) you emit warning in log (not throw IllegalStateException) and fallback to new Thread()

JDK itself does it in some cases! Please see java.util.concurrent.CompletableFuture#ASYNC_POOL (and code around it)

magicprinc avatar Nov 26 '23 15:11 magicprinc

What would you like to be configurable exactly? I'm not sure I understand.

If you deploy a verticle with the VIRTUAL_THREAD threading model, make sure it's running on a compatible JVM.

tsegismont avatar Nov 30 '23 14:11 tsegismont

The long story short: tests, test environments, CI profiles, JDK11-21, desire for VT, annotations to configure Verticles…

boolean fallbackToCachedThreadPool = "true".equalsIgnoreCase(System.getProperty("vertx.vt.fallback", System.getenv("VERTX_VT_FALLBACK")));

And then: isVirtualThreadAvailable() == true virtualThreadExecutor == Executors.newCachedThreadPool()

This will smooth out the migration to JDK21

magicprinc avatar Nov 30 '23 20:11 magicprinc

so you would like to use ThreadingModel.VIRTUAL_THREAD in JDK 17 without an error ?

vietj avatar Nov 30 '23 21:11 vietj

@vietj With this explicit env var VERTX_VT_FALLBACK=true - yes 🤦‍♂️ Just don't get me wrong: this is not for production, but tests, test stage, CI, etc

magicprinc avatar Nov 30 '23 23:11 magicprinc

I'm afraid we cannot do that because it would deliver wrong expectations.

I think in your application you should copy have a field copying the VIRTUAL_THREAD value and set it accordingly, e.g.

public static class VirtualThreadEnv { public static final ThreadingModel THREADING_MODEL = jvmSupportsVirtualThreads() ? ThreadingModel.VIRTUAL_THREAD : ThreadingModel.WORKER; }

and use that

On Fri, Dec 1, 2023 at 12:51 AM Andrej Fink @.***> wrote:

@vietj With this explicit env var VERTX_VT_FALLBACK=true - yes 🤦‍♂️

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

vietj avatar Dec 01 '23 08:12 vietj