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

  Рет қаралды 15,895

Made Easy

Made Easy

Күн бұрын

What is a Virtual Thread?
Like a platform thread, a virtual thread is also an instance of java.lang.Thread. However, a virtual thread isn't tied to a specific OS thread. A virtual thread still runs code on an OS thread. However, when code running in a virtual thread calls a blocking I/O operation, the Java runtime suspends the virtual thread until it can be resumed. The OS thread associated with the suspended virtual thread is now free to perform operations for other virtual threads.
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.
JEP : openjdk.org/je...
OpenJDK : openjdk.org/
Tags : #java #openjdk #jdk20 #jdk21 #jdk19 #java #javabasics #javaconcepts #javaprogramming #javamultithreading #RoadTo21

Пікірлер: 34
@zeppelinmexicano
@zeppelinmexicano 3 ай бұрын
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.
@Pyrotiksilence
@Pyrotiksilence 10 ай бұрын
20mb per platform thread is not accurate. It’s typically going to be closer to 1-2mb to create a platform thread in Java.
@ShreeGodmeshwarEnterprises
@ShreeGodmeshwarEnterprises 11 ай бұрын
Can't wait to implement this virtual thread into live project
@vikrantdhawan4062
@vikrantdhawan4062 10 ай бұрын
Great video!! just a suggestion , some intro about video will help lister to understand now content is starting be ready
@SmartDev-jl1wp
@SmartDev-jl1wp Жыл бұрын
Create videos on Java features as well
@MadeEasyTech
@MadeEasyTech Жыл бұрын
Sure
@tirunagariuttam
@tirunagariuttam 7 ай бұрын
@MadeEasyTech I liked the way you explained the topic. Please do make a full video on core java. Thanks.
@francisantony12
@francisantony12 8 күн бұрын
This was a very good presentation. Thank You
@MadeEasyTech
@MadeEasyTech 6 күн бұрын
Glad you enjoyed it!
@djricky89999
@djricky89999 24 күн бұрын
Sorry consist threads in the cpu??
@santhoshkrishnan5568
@santhoshkrishnan5568 22 күн бұрын
20 MB per platform thread?
@developer-zl8xt
@developer-zl8xt 11 ай бұрын
Really helpful
@thangamanikasi
@thangamanikasi 4 ай бұрын
Awesome... Thanks... Could you please share the github URL for this source code?
@khmarbaise
@khmarbaise 10 ай бұрын
Congrats on that great video. Thank you.
@longshin4299
@longshin4299 10 ай бұрын
1 Thread 20MB memory or 2MB?
@chamanjain9843
@chamanjain9843 6 ай бұрын
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?
@alessioantinoro5713
@alessioantinoro5713 4 ай бұрын
Platform thread and os thread are (almost) the same thing. Then, in case on any blocking operation, the platform thread is released to be re-used anywhere, while the code blocks and waits, once the request completes, the virtual thread will receive a new available platform thread and continue it's execution. The os has no idea this happened, only the JVM knows. Too there are some operation (like the synchronized block) that will block the platform thread until the request is done.
@priyankagutte8175
@priyankagutte8175 4 ай бұрын
very nice video, keep it up
@devilhorrible6715
@devilhorrible6715 5 ай бұрын
Can you share the code snippet???
@vikrantdhawan4062
@vikrantdhawan4062 10 ай бұрын
Can I work with your on these videos
@imranmomin4571
@imranmomin4571 7 ай бұрын
It occupy 2MB not 20MB.
@PixelHamster
@PixelHamster Жыл бұрын
What are you using for TTS ?
@djricky89999
@djricky89999 24 күн бұрын
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!
@dev50107
@dev50107 11 ай бұрын
Awesome ❤
@ravibmsit
@ravibmsit 8 ай бұрын
Excellent content .. To the point and very high quality narration !! Thanks for sharing this knowledge with us :)
@priyagutte293
@priyagutte293 4 ай бұрын
👍 yeah
@anonymous83245
@anonymous83245 5 ай бұрын
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 * 1000000 + (500ns + 500ns)))
@k2ketan100
@k2ketan100 10 ай бұрын
It takes 1mb for 64bit jvm per thread
@grzegorzt5245
@grzegorzt5245 8 ай бұрын
why 20MB per thread ?
@hfislwpa
@hfislwpa 2 ай бұрын
Great video thank you!
@MadeEasyTech
@MadeEasyTech Ай бұрын
Glad you liked it!
@techlover551
@techlover551 11 ай бұрын
I can see that your content quality is improving. Keep it going.
@MadeEasyTech
@MadeEasyTech 11 ай бұрын
I appreciate that!
Virtual Threads in Java 21
17:22
Will Tollefson
Рет қаралды 4,6 М.
How To Get Married:   #short
00:22
Jin and Hattie
Рет қаралды 21 МЛН
Шок. Никокадо Авокадо похудел на 110 кг
00:44
🍉😋 #shorts
00:24
Денис Кукояка
Рет қаралды 3,4 МЛН
Остановили аттракцион из-за дочки!
00:42
Victoria Portfolio
Рет қаралды 3,7 МЛН
Java Virtual Threads - Reactive Programming Killer?
13:57
Viraj Shetty
Рет қаралды 19 М.
Java 21 new feature: Virtual Threads #RoadTo21
33:35
Java
Рет қаралды 64 М.
Java 21 Is Good?! | Prime Reacts
27:08
ThePrimeTime
Рет қаралды 239 М.
Spring Tips: Virtual Threads
50:31
SpringDeveloper
Рет қаралды 14 М.
Project Loom - Structured Concurrency
36:24
Java
Рет қаралды 15 М.
Asynchronous Programming in Java using Virtual Threads, Venkat Subramaniam
49:16
Bulgarian Java User Group
Рет қаралды 12 М.
Java Virtual Threads and Scalability Of Enterprise Applications
12:06
How To Get Married:   #short
00:22
Jin and Hattie
Рет қаралды 21 МЛН