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.

Comparing performance: Platform versus virtual threads

Comparing performance: Platform versus virtual threads - Java Tutorial

From the course: Advanced Java: Threads and Concurrency

Comparing performance: Platform versus virtual threads

- [Narrator] While talking about performance, it's important to understand that virtual threads are not faster threads. They do not run code any faster than platform threads. The idea is to create more number of them that is to provide scale and not speed. So let's imagine creating one million platform threads. This is a huge number and it's quite obvious that it'll take a huge amount of text space. In this code, From line seven to nine, I'm spawning one million platform threads. A small thing here, I've use the thread.ofplatform factory method to do so instead of the conventional way of instantiating the thread class. When I ran it, it took 172 seconds to spawn this amount of threads. This could slightly vary depending on the available computing resources like memory or RAM to be precise. Let me comment out these lines now. And. Uncomment these lines. Now let's see what it takes to spawn one million virtual threads. I have the same code here, but in line 17, you can see that I create…

Contents