javafibersproject-loom

Detect Project Loom technology as missing or present JVM at runtime


Project Loom is now available in special early-release builds of Java 16.

If I were to run my Loom-based app on a Java implementation lacking in the Project Loom technology, is there a way to detect that gracefully early in my app launching?

I want to write code something like this:

if( projectLoomIsPresent() )
{
    … proceed …
}
else
{
    System.out.println( "ERROR - Project Loom technology not present." ) ;
}

How might I implement a projectLoomIsPresent() method?


Solution

  • Method 1:

    return System.getProperty("java.version").contains("loom");
    

    Method 2:

    try {
        Thread.class.getDeclaredMethod("startVirtualThread", Runnable.class);
        return true;
    } catch (NoSuchMethodException e) {
        return false;
    }