From the course: Top Features of Java 21
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
What are virtual threads? - Java Tutorial
From the course: Top Features of Java 21
What are virtual threads?
- [Instructor] One of the biggest changes in Java 21 is that it's now much easier to write scalable, multi-threaded applications. This is using a new feature called Virtual Threads. A thread is where your code executes, and there's always at least one in an application. Even if it's just a simple Hello World app, that will be running on a single thread. However, it's common to have multiple threads running at the same time, so that multiple things can happen at once. One pattern that's often used is to have one thread-per-request. So each time a request is sent in your application it needs a thread to run on, and it uses that one thread for the whole duration. And another request can run on another thread at the same time. This makes it easy to work with. For example, if an exception is thrown in the request, you can follow the stack trace because everything happened on the same thread. It's easy to understand and easy…