JDK 19 | Java Virtual Threads | Detailed Explanation With Example | JavaTechie

  Рет қаралды 13,976

Java Techie

Java Techie

Жыл бұрын

The concept of “Virtual threads” has gained considerable attention in recent times. Many programming languages are updating their thread libraries to support the Virtual Threading feature. Java introduces the virtual thread as a preview feature in the Java 19 release. This tutorial provides a deep introduction to the thread from the basic to the in-depth level of it in order to express the benefit of virtual threads, and the advantages they offer compared to conventional thread creation methods.
#JavaTechie #JDK19 #VirtualThread
Spring boot microservice Premium course lunched with 70% off 🚀 🚀
Hurry-up & Register today itself!
COURSE LINK : javatechie5246.ongraphy.com/
PROMO CODE : JAVATECHIE50
GitHub:
github.com/Java-Techie-jt/vir...
Blogs:
/ javatechie
Facebook:
/ javatechie
Join this channel to get access to perks:
kzfaq.infojoin
guys if you like this video please do subscribe now and press the bell icon to not miss any update from Java Techie
Disclaimer/Policy:
--------------------------------
Note : All uploaded content in this channel is mine and its not copied from any community ,
you are free to use source code from above mentioned GitHub account

Пікірлер: 46
@francksgenlecroyant
@francksgenlecroyant 4 ай бұрын
I love the Java Community Process and what it's doing to improve the Java language!
@supun_sandaruwan
@supun_sandaruwan 5 күн бұрын
Great Explanation sir ♥
@gopisambasivarao5282
@gopisambasivarao5282 Жыл бұрын
Thanks, Basant, for new future on Java 19 Virtual Thread architecture Appreciate your efforts.
@arjun-fl5eh
@arjun-fl5eh Жыл бұрын
Thanks for your videos. It helps a lot❤. If possible, try making a video or series on new features from JDK9 or JDK 11.
@kumarabhishek7877
@kumarabhishek7877 Жыл бұрын
Great Explanation sir, Jai Jagannath, May god bless you with good health.
@Deepakblg97
@Deepakblg97 5 ай бұрын
Awsome thank you sir ❤
@sameersayed5643
@sameersayed5643 Жыл бұрын
Thanks
@manikantareddy7595
@manikantareddy7595 Жыл бұрын
Great summarization of virtual threads. Can't wait any more for the upcoming videos on the same. Appreciate all your efforts in publishing this awesome content Many Thanks 😊
@hackwithharsha
@hackwithharsha Жыл бұрын
is it like event loop implementation in other programming languages ? Thank You !!
@divyanshusingh6473
@divyanshusingh6473 5 ай бұрын
Queries: 1. Why is CPU utilisation calculated as 16%? Can you explain that, why’re we taking it as a pct of 1sec. Is CPU blocked for whole 1 sec? 2. While showcasing whether virtual thread will release PT when blocked, you’re printing details for first VT only, sleeping for all 10. Why not just create 1 VT, and test?
@rishiraj2548
@rishiraj2548 Жыл бұрын
🙏👍
@sajid.farooqi8074
@sajid.farooqi8074 Жыл бұрын
Hi @Basant Sir ، Kindly plan a multi threading programing playlist as there is no such proper playlist with real time use cases available on KZfaq.
@Javatechie
@Javatechie Жыл бұрын
Okay Sajid .
@subba18
@subba18 Жыл бұрын
How many threads do you get per each spring boot tomcat server? How do you change this setting?
@rajjaiswal4769
@rajjaiswal4769 2 күн бұрын
Why you used join() method for all virtual threads ? I tried doing running same snippet without join method it was not printing anything for 0th index , can anyone help ?
@ravitez
@ravitez Жыл бұрын
Hey @Basant , Thanks for the video. One basic question, is it true that we can create any number of threads based on the Ram size ?, my understanding is the number of platform threads is equal to the number of cores in the machine we use. Is it not true ?
@Javatechie
@Javatechie Жыл бұрын
Yes that's 100% true, even though you will create more threads concurrently only 4 threads will execute if Ram size is 4.
@sivannarayanapenumala1840
@sivannarayanapenumala1840 20 күн бұрын
Will you be able to upload this PPT or documentation in github?? Or in the README file??
@nirajosh
@nirajosh Жыл бұрын
Nice explaination man but one question, about last 3 mins of your video, Where you are creating virtual threads and platform thread & starting it. My question is, When you will start virtual thread then will it get map to platform thread ? If so then why directly mapping to platform thread is more time consuming ?
@Javatechie
@Javatechie Жыл бұрын
Creating VT is not time consuming that's what I show in video last example
@raghuvardhansaripalli9636
@raghuvardhansaripalli9636 27 күн бұрын
Mega Star (Basant): Thank you for this information. I have a doubt. As virtual threads are residing in heap memory. if we increase the count of virtual threads then heap memory increases which leads to JVM performance issues. So what is the secret/logic/magic exists without having JVM performance issues . can you pls tell me in brief ?
@Javatechie
@Javatechie 27 күн бұрын
Yes you are absolutely correct Virtual threads have a smaller memory footprint compared to traditional (OS) threads. However, each virtual thread still consumes some heap memory for its stack and associated objects. Increasing the number of virtual threads will increase the total heap memory usage. but still we can play with memory tuning to mitigate it partially like Ensuring virtual threads are not lingering unnecessarily. Properly manage the lifecycle of virtual threads to release resources as soon as they are no longer needed.also we can think about improving GC algo to make it better by profiling memory usages like JConsole or any other profiling tool .
@Mronline-xyz
@Mronline-xyz 3 ай бұрын
Thanks alot Sir..🙏
@muralikrishna6044
@muralikrishna6044 Жыл бұрын
What is the usage of threads in our applications😊
@amithdk3595
@amithdk3595 Жыл бұрын
What happens to Thread Local ? Will the Virtual thread carry it?
@k283535
@k283535 11 ай бұрын
ThoughtPut - work done by cpu in a given time
@sureshmanne7245
@sureshmanne7245 Жыл бұрын
In the world of cloud era, how best is this virtual thread impact? Can you summarize the benefits in view of cloud comparison..
@Javatechie
@Javatechie Жыл бұрын
Okay i will do some R&D with cloud and update you
@DreamDropsTV
@DreamDropsTV 10 ай бұрын
the result is so obvious if you want to handle 1000+ no. of requests with normal native threads you will have to spin up multiple instances of that particular application or scale up horizontally or vertically. But with virtual threads same target can be achieved using a low config instance. And cloud is not free it charges fee as Pay as per usage model. So with the usage of native threads be prepared for high amount of bills .
@hun73rentertainment76
@hun73rentertainment76 Жыл бұрын
To address the issue of thread per request, wbclient is also there then why virtual thread?
@Javatechie
@Javatechie Жыл бұрын
Buddy you might not be getting the concept properly could you please check again
@theniteshkumarjain
@theniteshkumarjain Жыл бұрын
Few questions 1. Why the 100ms which is actually processing the logic is not calculated during this process 2. If only 16% cpu is used then how are we getting memory out of bound exception
@Javatechie
@Javatechie Жыл бұрын
This is just a high level benchmarking buddy. The number could be very in the real system
@hanumanthram6754
@hanumanthram6754 Жыл бұрын
IntStream.range(0, totalThread) .mapToObj( thCount -> Thread.ofVirtual().unstarted(() -> { // out.println("Virtual thread "+ thCount); })).toList(); without print statement: millis used to launch 10000 vthreads: 41ms millis used to launch 10000 pthreads: 735ms With print statement: millis used to launch 10000 vthreads: 1865ms millis used to launch 10000 pthreads: 813ms when print statement is there, the virtual thread took more time when compared to the platform thread. can you please explain why>
@tejutitare
@tejutitare 5 ай бұрын
When you use Prinln statement JVM use main thread which is nothing but platform..
@vishaldeshmukh4459
@vishaldeshmukh4459 7 ай бұрын
Can we create pool of virtual threads like ThreadPoolTaskExecutor?
@Javatechie
@Javatechie 7 ай бұрын
Yes we can and that's my next video using spring boot.
@ishantbhatia3194
@ishantbhatia3194 Жыл бұрын
Need more clarification, stil have doubt, this can be done in reactive programming
@manikantareddy7595
@manikantareddy7595 Жыл бұрын
The short answer is yes, but you loose the profiling and observability of your application if you use reactive libraries also thinking reactive and writing asynchronous code is not so easy and exception handling is also pain. It takes time to understand since we're accustomed to writing synchronous style code. Structured concurrency is another JEP aims to solve this issue. All in all you get all the benefits of asynchronosity without writing asynchronous code. I hope this answers your question
@sommyaruproy8405
@sommyaruproy8405 Жыл бұрын
Reactive is hard to code and debug and restrictive.
@ishantbhatia3194
@ishantbhatia3194 Жыл бұрын
@@sommyaruproy8405 we have desiged rate limiter using reactive, it was quite easy i guess. But might be hard in other use cases
@Javatechie
@Javatechie Жыл бұрын
Guys reactive and virtual thread both context is completely different please give me sometime i will help with your Confusion. Single statement it's not comparable
@mayurbhole8271
@mayurbhole8271 Жыл бұрын
​@@manikantareddy7595 I think reactive programming using PT thread ,then we can't achieve more request as come with visual thread
@shaikakbarali5257
@shaikakbarali5257 9 ай бұрын
Total CPU time for single request = 0.1 (Request) + (0.1 Response) = 0.2 ms ??. Why was the IO (DB and other services ) 100 ms was omitted from Total CPU time for single request calculation ?? Am i missing anything basanth?
@DreamDropsTV
@DreamDropsTV 6 ай бұрын
why will a network call will have any cpu usage ? . The cpu is not processing data at that time, its just waiting for response from DB or other microservice. Hence your cpu didn't got utilized properly. Whereas virtual thread ensures, when these scenario occurs platform thread is detached and used for other requests as a carrier thread. Improving scalability of app and maximizing the cpu usage.
@shaikakbarali5257
@shaikakbarali5257 6 ай бұрын
@@DreamDropsTV thanks mayur
Effortlessly Consume GraphQL APIs with Spring Boot | @Javatechie
27:31
Java 21 new feature: Virtual Threads #RoadTo21
33:35
Java
Рет қаралды 58 М.
Looks realistic #tiktok
00:22
Анастасия Тарасова
Рет қаралды 98 МЛН
Wait for the last one! 👀
00:28
Josh Horton
Рет қаралды 170 МЛН
SOLID Design Principles in java with Example | JavaTechie
34:44
Java Techie
Рет қаралды 178 М.
Java's Virtual Threads - Next Steps
37:52
Java
Рет қаралды 14 М.
Java Virtual Threads - Reactive Programming Killer?
13:57
Viraj Shetty
Рет қаралды 15 М.
Java 21 API New Features #RoadTo21
16:48
Java
Рет қаралды 38 М.
Spring Boot - Introduction to Reactive Programming | JavaTechie
12:46
КРУТОЙ ТЕЛЕФОН
0:16
KINO KAIF
Рет қаралды 5 МЛН
1$ vs 500$ ВИРТУАЛЬНАЯ РЕАЛЬНОСТЬ !
23:20
GoldenBurst
Рет қаралды 1,7 МЛН
Первый обзор Galaxy Z Fold 6
12:23
Rozetked
Рет қаралды 432 М.
Samsung Galaxy 🔥 #shorts  #trending #youtubeshorts  #shortvideo ujjawal4u
0:10
Ujjawal4u. 120k Views . 4 hours ago
Рет қаралды 4,7 МЛН