From the course: Java SE 21 Developer (1Z0-830) Cert Prep

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Virtual threads, part 2

Virtual threads, part 2

- Now as we mentioned, the virtual thread class isn't public, so you can't say new virtual thread. Instead, you have several ways of creating a virtual thread and getting it to execute your code. One of them is a method in the thread class, start virtual thread, and you give it a runnable and off it goes. There's also a builder. The builder is likely to be the most useful mechanism in many cases, maybe not the most useful, but it's one of the two more likely ways of doing it. With a thread builder, what you can do, the thread.builder interface is actually, as you see, a member of the thread class itself. You can say thread.ofvirtual, and it will give you a thread.builder implementation. And using that, you can create a new thread and off you go. However, because there are certain differences between the capabilities of platform threads where you can actually set a priority and it's meaningful, you can set it as non…

Contents