Java 19 Virtual Threads - JEP Café #11

Ғылым және технология

JavaOne is back! ➱ oracle.com/javaone
What are virtual threads, the new model for threads, added to the JDK 19 as a preview feature by the Loom project.
⎯⎯⎯⎯⎯⎯ Chapters ⎯⎯⎯⎯⎯⎯
0:00 Intro
0:42 What are preview features, and how you can use them
3:34 What are Virtual Threads about?
4:21 Goals of Virtual Threads
5:11 Cost of a platform thread and CPU usage
7:49 How to use Virtual Threads
9:11 Using ExecutorServices with Virtual Threads
11:04 ThreadLocals and Synchronization
11:19 Synchronization, pinned threads and locks
13:14 Final words and outro
⎯⎯⎯⎯⎯⎯ Resources ⎯⎯⎯⎯⎯⎯
◦ The Dev.java website ➱ dev.java/
◦ JEP 425: Virtual Threads (Preview) ➱ openjdk.java.net/jeps/425
◦ JDK 18 ➱ openjdk.java.net/projects/jdk/18
◦ JDK 19 ➱ openjdk.java.net/projects/jdk/19
◦ OpenJDK ➱ openjdk.java.net/
◦ Oracle Java ➱ www.oracle.com/java/
Tags: #Java #Java19 #Loom #OpenJDK #JDK #JDK19 #ConcurrentProgramming #JEPCafe #InsideJava

Пікірлер: 81

  • @jpomykala
    @jpomykala2 жыл бұрын

    I would love to see some patterns and real world problems solved with the new virtual threads 😊

  • @romanpleshkov1125

    @romanpleshkov1125

    Жыл бұрын

    golang?

  • @kappaj01
    @kappaj012 жыл бұрын

    Agree - some code in action with best practices will be super helpful.

  • @IhorParashynets
    @IhorParashynets2 жыл бұрын

    yes, some code in action and best practices would be nice to see... Thanks!

  • @nO_d3N1AL
    @nO_d3N1AL2 жыл бұрын

    Really like the explanation of the motivation, it addressed the question of "but why is this a problem when we have thread pools?" I think the preview feature explanation in the first few minutes could be removed though, it's not the first preview feature and I'm sure the whole idea of previews is explained elsewhere but still, a nice reminder.

  • @ivandenysenko
    @ivandenysenko2 жыл бұрын

    Yes, please! It would be great to see some examples and patterns!

  • @java

    @java

    2 жыл бұрын

    Stay tuned please!

  • @prod.blindfucker
    @prod.blindfucker2 жыл бұрын

    Great video. Love to see examples of Virtual Threads!

  • @java

    @java

    2 жыл бұрын

    More to come!

  • @HarmeetSingh0013
    @HarmeetSingh00132 жыл бұрын

    Wow... a super awesome explanation and I am really excited to explore Virtual threads.

  • @java

    @java

    2 жыл бұрын

    Great to hear!

  • @TomekSamcik69
    @TomekSamcik692 жыл бұрын

    Virtual threads are magnifique !

  • @tomassatas5345
    @tomassatas5345 Жыл бұрын

    4 minutes into the video and finally you are on the topic.

  • @ahmadfx8962
    @ahmadfx89622 жыл бұрын

    welcome back, yes we would like to see examples

  • @Sergey111111
    @Sergey111111 Жыл бұрын

    Gosh can't wait when I start use all this staff like semaphores and lock I learned for interviews!

  • @VisruthCV
    @VisruthCV2 жыл бұрын

    Very informative video, thanks for publishing! 11:54 is very important point!

  • @VisruthCV

    @VisruthCV

    2 жыл бұрын

    Here, the ReentrantLock should be declared as an instance variable, i.e. in the class of "key" passed in "synchronised (key)" otherwise it will not act as a replacement of synchronised block.

  • @marcoborgna
    @marcoborgna2 жыл бұрын

    I'm super thrilled by Virtual Threads but I feel will take so long before using in PROD env

  • @mars009
    @mars0099 ай бұрын

    Some example and how things work under the hood would be amazing episodes.

  • @wassifmeskine3328
    @wassifmeskine3328 Жыл бұрын

    Very good explanation 😀

  • @java

    @java

    Жыл бұрын

    Thanks! 😃

  • @itlearner1175
    @itlearner1175 Жыл бұрын

    Nicely explained, thank you! Question what would be the impact of this on reactive programming?

  • @sovrinfo
    @sovrinfo2 жыл бұрын

    Thanks!

  • @ricklee-tj7bu
    @ricklee-tj7bu Жыл бұрын

    Greate vid!! A thread reserves upfront 20MB in memory? can i get more detail information about it?

  • @mikeb6125
    @mikeb61252 жыл бұрын

    Good to see some example code

  • @dmitrypereverzev9884
    @dmitrypereverzev98842 жыл бұрын

    It would be nice to see how virtual threads work under the hood. How to handle exceptions in VT. Exception handling patterns. Are these preemptive or cooperative?

  • @bentels5340
    @bentels53402 жыл бұрын

    Of course, code examples are always good.

  • @java

    @java

    2 жыл бұрын

    Absolutely!

  • @NastyaSmirnova
    @NastyaSmirnova2 жыл бұрын

    Great session. Thanks! I would like to see some code in action as well.

  • @java

    @java

    2 жыл бұрын

    Coming soon!

  • @HarmeetSingh0013
    @HarmeetSingh00132 жыл бұрын

    I am really happy to give you coffee from my side :D , but you should discuss patterns and ways of using virtual threads.

  • @ahmedbouchaibi6111
    @ahmedbouchaibi61112 жыл бұрын

    The end of Reactor pattern that i hate him , end to learn of go that i hate him also, I hope it will be in production as soon as possible, Thanks i love java !!!!!!

  • @thezhang4269
    @thezhang42692 жыл бұрын

    Because my English is not good, so I try to describe it as accurately as possible。 After consulting relevant materials and doing some practice, I did find that the JVM will replace blocked IO with NiO when it detects virtual threads. So my question is, since the virtual thread is running on the carrier thread, the carrier thread will still be blocked when the read() of NiO is executed, right? If the carrier thread is blocked as I said, the thread must be suspended. As a result, many thread switches will lead to a decline in CPU utilization. I really hope someone can solve my doubts. Thanks.

  • @hello-world1
    @hello-world1 Жыл бұрын

    can javascript run on virtual threads in graalvm?

  • @slr150
    @slr1502 жыл бұрын

    How does this affect happens-before ordering, especially on systems with weak hardware memory models?

  • @DavidDLee

    @DavidDLee

    2 жыл бұрын

    Same JVM memory model

  • @VictorHernandez-qt2xx
    @VictorHernandez-qt2xx Жыл бұрын

    Can you please highlight some differences between Kotlin coroutines and virtual threads?

  • @DeepakLalchandaniProfile
    @DeepakLalchandaniProfile2 жыл бұрын

    Has anyone written an in depth article of virtual threads with code examples,please share the article

  • @romulopaiva7070
    @romulopaiva70702 жыл бұрын

    Congrats!!! Very cool explanation! Next step: show me the code! 😁

  • @java

    @java

    2 жыл бұрын

    Stay tuned...

  • @MichaKuda
    @MichaKuda2 жыл бұрын

    which extension has been dropped?

  • @LannisterFromDaRock
    @LannisterFromDaRock2 жыл бұрын

    Isn't threads using something like 2 MB RAM for the stack each? 20 MB sounds way too much!

  • @ishcatu

    @ishcatu

    2 жыл бұрын

    Yes, I thought the same and according to Tomasz Nurkiewicz's talk at JChampion Conf it's 1MiB: kzread.info/dash/bejne/oJOMtLelmsnMpZM.html

  • @staffeng

    @staffeng

    2 жыл бұрын

    I was also surprised by this. Wild stackoverflow searches tells me it's more in the lines of a few hundred KBs, like between 32KB to 512KBs. I don't know who's right here.

  • @DavidDLee

    @DavidDLee

    2 жыл бұрын

    The Java stack is configurable, defaults are platform specific, but the range is something like 128K ~ 1M. The native stack is 2 MB by default for Linux. However, both these values are for virtual memory, not physical memory, so it's more of a limit rather than actual cost.

  • @andmal8
    @andmal8 Жыл бұрын

    Coding in action would be great. Thank you!

  • @Concat76
    @Concat76 Жыл бұрын

    Thank you for the informative presentation, and we wish to see code.

  • @rafsmol
    @rafsmol2 жыл бұрын

    Certainly your coffee ended to early. I'm eager to hear more about the virtual threads.

  • @java

    @java

    2 жыл бұрын

    Please stay tuned!

  • @abdulkerimfettahoglu
    @abdulkerimfettahoglu2 жыл бұрын

    Sir, Could you please use your holding hand to take a sip from coffee. I don't know why but I focused on that throughout the video :D

  • @sommyaruproy8405
    @sommyaruproy84052 жыл бұрын

    Show some examples with vthreads with blocking queries to db.

  • @DeepakLalchandaniProfile

    @DeepakLalchandaniProfile

    2 жыл бұрын

    Yes agreed please show us examples of virtual threads with blocking queries to db ?

  • @avalagum7957
    @avalagum79572 жыл бұрын

    Yes, I would like to see some example code about that ReentrantLock. Thank you for this video.

  • @VisruthCV

    @VisruthCV

    2 жыл бұрын

    The ReentrantLock should be declared as an instance variable, i.e. in the class of "key" passed in "synchronised (key)" otherwise it will not act as a replacement of synchronised block.

  • @linuxuser1234
    @linuxuser12342 жыл бұрын

    @Java can you JEP and netcdf tutorial

  • @staffeng
    @staffeng2 жыл бұрын

    I feel the "cost of a platform thread" needs a lot more explanation in a separate video -- perhaps with a few demos. I always read, most likely from incorrect sources, that thread creation and context switching is expensive in terms of CPU. I imagined it would in the order of a few tens of milliseconds. I'm surprised to learn that it takes just 1ms but the real cost is in the inability to 100s or 1000s of threads to keep the CPU busy. However, why is that in the apps I've worked on which had performance issues due to blocking networking calls I always see the CPU at near 100%? I thought it was due to all the thread context switching and garbage collection taking up the CPU more than my app's code but looks like it's not as per this explanation.

  • @LannisterFromDaRock

    @LannisterFromDaRock

    2 жыл бұрын

    It's only a guess, but I think the 100% CPU usage was caused by iowait, especially if the OS was Linux.

  • @DavidDLee

    @DavidDLee

    2 жыл бұрын

    I think the explanation was simplified but still pretty good. Could have mentioned cost of context switching, limited ability to schedule too many kernel threads. Could also mentioned limited capacity or diminished capacity when dependencies take longer to complete.

  • @bentels5340

    @bentels5340

    2 жыл бұрын

    Your CPU is probably at 100% because all of your threads are waiting -- it's constantly switching, trying to find a thread ready to do work.

  • @oneextrabit
    @oneextrabit2 жыл бұрын

    Pooling threads in order to limit the number of conncetions to the DB doesn't sound like a good idea. Isn't it better to use a Semaphore in this case?

  • @alexhali6003
    @alexhali60032 жыл бұрын

    Need some code examples)

  • @jay_sensz
    @jay_sensz2 жыл бұрын

    The code example at 10:50 is misleading. The semaphore doesn't actually do anything in this scenario and all queries will be executed sequentially. It would only make sense if you wrap the for-loop's content with `new Thread(()->{...}).start();`

  • @DeepakLalchandaniProfile

    @DeepakLalchandaniProfile

    2 жыл бұрын

    Could you provide a working java example for the one referred at 10:50

  • @jay_sensz

    @jay_sensz

    2 жыл бұрын

    @@DeepakLalchandaniProfile ?! I did

  • @DeepakLalchandaniProfile

    @DeepakLalchandaniProfile

    2 жыл бұрын

    @@jay_sensz im mentioning about new Thread(()->{...}).start(); Can you share a working example please

  • @jay_sensz

    @jay_sensz

    2 жыл бұрын

    @@DeepakLalchandaniProfile Semaphore semaphore = new Semaphore(10); for(Query query: queries){ semaphore.acquire(); new Thread(()->{ try{ query.run(); }finally{ semaphore.release(); } }).start(); }

  • @DeepakLalchandaniProfile

    @DeepakLalchandaniProfile

    2 жыл бұрын

    @@jay_sensz how to execute it using public static void main method ?? .do you have the full working example on github ?

  • @bororobo3805
    @bororobo38052 жыл бұрын

    golang and java

  • @oneextrabit
    @oneextrabit2 жыл бұрын

    Can someone elaborare more on the resource utilisation at kzread.info/dash/bejne/nn-HtaSvgqfThMo.html

Келесі