Understanding Java Virtual Threads | Java 21, 20, 19 | Made Easy

preview_player
Показать описание
What is a Virtual Thread?

Virtual threads are implemented in a similar way to virtual memory. To simulate a lot of memory, an operating system maps a large virtual address space to a limited amount of RAM. Similarly, to simulate a lot of threads, the Java runtime maps a large number of virtual threads to a small number of OS threads. Unlike platform threads, virtual threads typically have a shallow call stack, performing as few as a single HTTP client call or a single JDBC query. Although virtual threads support thread-local variables, you should carefully consider using them because a single JVM might support millions of virtual threads. Virtual threads are suitable for running tasks that spend most of the time blocked, often waiting for I/O operations to complete. However, they aren't intended for long-running CPU-intensive operations.

Tags : #java #openjdk #jdk20 #jdk21 #jdk19 #java #javabasics #javaconcepts #javaprogramming #javamultithreading #RoadTo21
Рекомендации по теме
Комментарии
Автор

Java has come a long way, baby. Virtual threads, streams, lambdas, even a new switch, just in the last few years. When you factor in the enormous base and the fact that it just works, even if more verbose than some of the newer languages, it's a pretty undeniable force of coding nature. I remember all the "Java killer" threats coming out of MS when dotNet was released. Pure marketing bullshit.

zeppelinmexicano
Автор

Can't wait to implement this virtual thread into live project

ShreeGodmeshwarEnterprises
Автор

Excellent content ..
To the point and very high quality narration !!
Thanks for sharing this knowledge with us :)

ravibmsit
Автор

20mb per platform thread is not accurate. It’s typically going to be closer to 1-2mb to create a platform thread in Java.

Pyrotiksilence
Автор

Great video!!
just a suggestion, some intro about video will help lister to understand now content is starting be ready

vikrantdhawan
Автор

Create videos on Java features as well

SmartDev-jlwp
Автор

If I have virtual theads for example in my laptop I have 16gb of ram and I create virtual threads, how much 16gb of ram? Or do I create more? Will I have more speed for my heavy programmes? Explain to me well!

djricky
Автор

I have a question. Suppose I made an HTTP request using Java from a virtual thread, let's say using RestTemplate. Now, suppose that the response takes approximately 2 minutes. Does this mean the virtual thread will release this platform thread and OS thread and itself get blocked for the duration of 2 minutes?

Assuming the response arrives on port 8080, will it directly notify the virtual thread that the response has arrived, prompting it to wake up? Or will there be some OS thread that handles the response first and then informs the platform thread to wake up the virtual thread?

chamanjain
Автор

This was a very good presentation. Thank You

francisantony
Автор

I can see that your content quality is improving. Keep it going.

techlover
Автор

@MadeEasyTech I liked the way you explained the topic. Please do make a full video on core java. Thanks.

tirunagariuttam
Автор

Congrats on that great video. Thank you.

khmarbaise
Автор

Awesome... Thanks... Could you please share the github URL for this source code?

thangamanikasi
Автор

Q: how the cpu usage is calculated? A: total CPU usage = threads num * (computation time per thread / total time per thread) ; so the total cpu usage in this video: 0.8% ≈ 800 * ((500ns + 500ns) / (100ms * + (500ns + 500ns)))

anonymous