I was exploring the Virtual Threads in Project Loom. The Documents say it as straight forward with simple lines of code as below:
Thread.startVirtualThread(() -> {
System.out.println("Hello, Loom!");
});
Or
Thread t = Thread.builder().virtual().task(() -> { ... }).start();
I have tried both of them, For the first one, I receive an error
The method startVirtualThread(() -> {}) is undefined for the type Thread
And for the second one
- The method builder() is undefined for the type Thread
One browsing, found that lombok is required, Installed lombok as well. However it doesn't show up in Eclipse About section, I am able to use lombok, But still my issue is not resolved.
Below link show the documentation, I am referring to.
Sample Code:
public class threads {
public void simpleThread() {
Thread start = Thread.builder().virtual().task(() -> {
System.out.println("Hello World");
}).start();
Thread.startVirtualThread(() -> {
System.out.println("Hello, Loom!");
});
}
public static void main(String[] args) {
// TODO Auto-generated method stub
threads trd = new threads();
trd.simpleThread();
}
}

It looks like older versions of Eclipse is giving a compilation error when calling the new Thread methods related to Loom.
Please try to use the latest Eclipse (currently 2020-09) with an OpenJDK Project Loom Early-Access Build.
You can make sure that this is an Eclipse related issue by compiling and running your program directly from the command line (using
javacandjavacommands).