From the course: Advanced Java: Threads and Concurrency

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Things to keep in mind when using virtual threads

Things to keep in mind when using virtual threads - Java Tutorial

From the course: Advanced Java: Threads and Concurrency

Things to keep in mind when using virtual threads

- [Presenter] Virtual threads introduced with Project Loom have undoubtedly added bells and whistles to Java concurrency. However, it's also good to keep in mind a few important things to make the most of this new feature. With the traditional Java concurrency model, threads, more precisely platform threads, are a scarce resource that an application is using. This is why threads are pulled. However, with virtual threads, the story is different. They're available in ample amounts, so they're not meant to be pulled. The idea behind virtual threads is not for them to be managed as a scarce resource in an application. Instead, a virtual thread should represent a task itself. So with virtual threads, threads turn into application domain objects from a managed resource. If you ask how many virtual threads and application should create, the answer should obviously be the number of virtual threads is always equal to the number of concurrent tasks in our application. So what you need to…

Contents