Тёмный

Java 21: Virtual Threads - A different async/await explained with Code Examples 

Th30z Code
Подписаться 1,8 тыс.
Просмотров 9 тыс.
50% 1

Опубликовано:

 

29 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 22   
@Phauglin99
@Phauglin99 3 месяца назад
Excellent explanation and visualization on an actual problem, not just printing "Hello World" lines. Thank you!
@josedavidforero
@josedavidforero Месяц назад
Very clear explanation, thanks a lot.
@Asingh42
@Asingh42 10 месяцев назад
Now spring boot 3.2 supports virtual threads make a video on it how to use @Async with it
@SuperShahidAkhtar
@SuperShahidAkhtar Год назад
Thanks for examples
@th30z-code
@th30z-code Год назад
Thanks for checking them out! I hope they were helpful.
@yeshengwei79
@yeshengwei79 Год назад
Very informative! Well done👍
@th30z-code
@th30z-code Год назад
Thanks! I'm glad you enjoyed it
@thilankaliyanaarachchi984
@thilankaliyanaarachchi984 2 месяца назад
Quality content! Please keep them coming :)
@Anbu_Sampath
@Anbu_Sampath 8 месяцев назад
Nice examples.
@manojBadam
@manojBadam 4 месяца назад
Very good explanation
@RandomHandle120
@RandomHandle120 3 месяца назад
The whole point of async/await in other languages is code cleanliness. None of this addresses Java's biggest shortcoming: nested/callback code hell!
@th30z-code
@th30z-code 3 месяца назад
Java itself doesn't have many APIs with callbacks. all I/O and locks APIs, for example, looks synchronous. The problem is that since Java 8, lambdas and streams got abused (even in my examples, to quickly create functions). Also most of the "network framework" out there are still not leveraging virtual threads, since it's a major redesign to move away from the all the callback hell created to workaround async I/O limitations. But now the language allows to write cleaner code, so it's just a matter of choosing a newer/better set of libraries.
@RandomHandle120
@RandomHandle120 3 месяца назад
@@th30z-code You still can't, for example, write sequential-looking code that sends an HTTP request without blocking the UI thread. This was a problem in every language a while ago, and many fixed it by switching to an async/await model. Java refused to do anything about it, so to this day, you still have to write uglier, unmaintainable code riddled with callback lambdas to keep your app's UI responsive.
@th30z-code
@th30z-code 3 месяца назад
can you share a bit more? I haven't used any java UI framework lately, but my guess is that is just a "UI framework problem", meaning that the framework is still not leveraging virtual threads. If your "onClick()" for examples is run in a virtual thread you can use the HttpClient.sendSync() client, take locks and do other blocking stuff with a code that will look sequential and not blocking the UI.
@RandomHandle120
@RandomHandle120 3 месяца назад
@@th30z-code It's not a framework/library problem, it's a problem with the language itself. It doesn't matter what framework you're using, you simply cannot write sequencial, yet asynchronous code in Java until Oracle decides to implement some sort of async/await feature onto the language itself; until then, Java remains a terrible language to write asynchronous code in.
@th30z-code
@th30z-code 3 месяца назад
virtual threads are the async/await alternative. In the way they implemented there is no reason to add new keywords like async/await. java takes care of scheduling the threads by itself, since underneath is known which operations are "blocking I/O" and which are not. so you can think as it as "java adds the await where it is needed". so, if your code/framework uses virtual threads you now can write sequential code and it will be the same as using async/await in other languages. just try to write a simple example with a Thread.sleep() or an httpClient.send(), you'll see that it will actually look nice even without the async/await keyword.
Далее
Java 21 new feature: Virtual Threads #RoadTo21
33:35
Просмотров 64 тыс.
Witch changes monster hair color 👻🤣 #shorts
00:51
titan tvman's plan (skibidi toilet 77)
01:00
Просмотров 6 млн
Что нового в JDK 21
52:37
Просмотров 8 тыс.
Virtual Threads in Java 21
17:22
Просмотров 4,6 тыс.
Java Virtual Threads
9:06
Просмотров 38 тыс.
Java Virtual Threads - Reactive Programming Killer?
13:57
Teaching old Streams new tricks  By Viktor Klang
50:51
Witch changes monster hair color 👻🤣 #shorts
00:51