Launching 10 millions virtual threads with Loom - JEP Café #12

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

JavaOne is back! ➱ oracle.com/javaone
Live demo of the Java virtual threads from the JDK 19, previewing the Loom project.
⎯⎯⎯⎯⎯⎯ Chapters ⎯⎯⎯⎯⎯⎯
0:00 Intro
0:56 Reactive code versus blocking code
1:53 Creating and running platform and virtual threads with Loom
3:22 Introducing the VirtualThread class
3:55 Threads used by the JVM
4:06 Using a fork / join pool to run virtual threads
6:43 Making a virtual thread jump from one platform thread to another
7:59 Introducing continuations
9:04 Yielding a continuation
10:42 What is the price of blocking a virtual thread?
11:55 How many platform threads do you need to run your virtual threads?
13:34 Running 10 million virtual threads
14:25 When a virtual is pinned to a platform thread
15:38 Comparing classical synchronization and reentrant locks
18:13 Final words and outro
⎯⎯⎯⎯⎯⎯ Resources ⎯⎯⎯⎯⎯⎯
◦ The Dev.java website ➱ dev.java/
◦ JEP 425: Virtual Threads (Preview) ➱ openjdk.org/jeps/425
◦ JDK 19 ➱ openjdk.org/projects/jdk/19/
◦ OpenJDK ➱ openjdk.org/
◦ Oracle Java ➱ www.oracle.com/java/
Tags: #Java #Java19 #Loom #VirtualThreads #OpenJDK #JDK #JDK19 #ConcurrentProgramming #InsideJava

Пікірлер: 113

  • @themathmoth7393
    @themathmoth73932 жыл бұрын

    The JEP Café and the Inside Java Newscast were the best ideas for Java since introducing Lambdas.

  • @JosePaumard

    @JosePaumard

    2 жыл бұрын

    Waow! Lambdas! That's something! Thank you!

  • @sadiulhakim7814
    @sadiulhakim7814Ай бұрын

    Look at this amazing community, Java Community.

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

    We love code please continue

  • @svalyavasvalyava9867
    @svalyavasvalyava98678 ай бұрын

    what a wonderful, informative, and insightful video, thank you 😊

  • @AkhileshKumar-cs2kh
    @AkhileshKumar-cs2kh2 жыл бұрын

    Yes, Please. We want video on structured concurrency

  • @TheWhom
    @TheWhom10 ай бұрын

    I just discovered JEP Café. Omg... subscribed.

  • @java

    @java

    10 ай бұрын

    👍 enjoy... and feel free to spread the word!

  • @armandoprietopadron1906
    @armandoprietopadron19062 жыл бұрын

    Great video! Looking forward to the Structured Concurrency video.

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

    Nice presentation. The way you showed the JDK code increased my interest. I am going to do the same in my local. Thanks

  • @ravibmsit
    @ravibmsit6 ай бұрын

    Very insightful session !! Thanks !!

  • @berenger085
    @berenger0852 жыл бұрын

    Thanks. Always a pleasure enjoying my coffee here.

  • @AleksandarT10
    @AleksandarT102 жыл бұрын

    Great video, it would be good if you can make more videos on these topics!

  • @JosePaumard

    @JosePaumard

    2 жыл бұрын

    Thanks, will do!

  • @TheDoppelganger29
    @TheDoppelganger292 жыл бұрын

    Would like more on structured concurrency and its future plans. Fantastic video

  • @MyImprov

    @MyImprov

    2 жыл бұрын

    Same here!

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

    Awesome! Thank you very much José.

  • @java

    @java

    Жыл бұрын

    Glad you liked it!

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

    Excellent video, thanks!

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

    Un grand merci! I would love to see more about how Java uses virtual threads to make async programming easier! 🥰

  • @MakeItStik
    @MakeItStik2 жыл бұрын

    As usual another great video by Mr. Paumard. Please make such videos more frequently.

  • @JosePaumard

    @JosePaumard

    2 жыл бұрын

    Thank you, I really appreciate it! -- José

  • @Juanj0se22
    @Juanj0se227 ай бұрын

    thanks for sharing! very clear

  • @a0um
    @a0um2 жыл бұрын

    Reminds me of Erlang/Elixir. Great to see something similar in Java.

  • @indianakv
    @indianakv2 жыл бұрын

    Project Loom is blessing... now how the industry will replace reactive programming with Loom? so eager about it.

  • @A.n.a.n.d.
    @A.n.a.n.d.2 жыл бұрын

    This was just amazing. Looking forward to more of such talks.

  • @yonatanbenavraham7038
    @yonatanbenavraham70382 жыл бұрын

    Great video! Thanks! I would love another video about Structured Concurrency.

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

    Great explanation of Virtual Threads. If we could get more of the same with links to the code - that would be great. Thanks for a great presentation

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

    Very informative examples, great presentation. Keep it up. Thanks for publishing! Java is awesome 👍

  • @JosePaumard

    @JosePaumard

    2 жыл бұрын

    It is indeed! Thank you!

  • @feryadialoi2244
    @feryadialoi22442 жыл бұрын

    finally JEP cafe with some code hands on🔥

  • @GercioP
    @GercioP2 жыл бұрын

    Wow, this is marvelous! Thanks!

  • @cedricnabaa2357
    @cedricnabaa23572 жыл бұрын

    Thank you, waiting for the structured programming talk !

  • @seafront12
    @seafront122 жыл бұрын

    Nice video, looking forward to next one

  • @alexfalappa
    @alexfalappa2 жыл бұрын

    Please, do talk about Structured Concurrency, looking forward to it

  • @anhle3976
    @anhle39762 жыл бұрын

    Thank you, it's great video and I want to see Structure Concurrency next time too.

  • @Czarmzy
    @Czarmzy2 жыл бұрын

    Excellent episode every comfy.

  • @marancibia1971
    @marancibia19712 жыл бұрын

    Great video!

  • @user-xj5lx9tt7k
    @user-xj5lx9tt7k Жыл бұрын

    太棒了!希望Loom在正式发布后能让整个Java生态发生质的变化,让我们在性能和其他方面与其他新生语言一较高下!

  • @triettruong8200
    @triettruong82002 жыл бұрын

    I love simple explanation on complex topics like this. Thank you for your time and efforts to provide understandable piece of knowledge! Can't wait for the next topic. Btw, I was also drinking coffee while watching this.

  • @Gennys

    @Gennys

    Жыл бұрын

    I recommend watching some videos by Brian Goetz about the JVM and other java subjects if you like to dive deep into these kinds of things as well.

  • @Anbu_Sampath
    @Anbu_Sampath2 жыл бұрын

    Please do video on Structured concurrency.

  • @JosePaumard

    @JosePaumard

    2 жыл бұрын

    Will do!

  • @mingjunduan5916
    @mingjunduan59162 жыл бұрын

    Awesome, nice work

  • @JorgetePanete
    @JorgetePanete2 жыл бұрын

    The yield-resume sounds like a safe version of stopping and resuming a thread, pretty cool

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

    Amazing!

  • @simonmartinelli
    @simonmartinelli2 жыл бұрын

    Great video, as always

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

    Great presentation José!

  • @aturan-fo1qt
    @aturan-fo1qt2 жыл бұрын

    Thanks 👍

  • @12345ms
    @12345ms2 жыл бұрын

    Excellent content and so well explained; thank you, @José Paumard

  • @dgkaba
    @dgkaba2 жыл бұрын

    Merci just as amazing as loom

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

    Thanks a lot Great Video

  • @senthil87
    @senthil872 жыл бұрын

    Excellent presentation 👏

  • @alql77
    @alql772 жыл бұрын

    Amazing content!

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

    Thanks you a lot!

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

    Merci !

  • 2 жыл бұрын

    Amazing 👏!!!

  • @JosePaumard

    @JosePaumard

    2 жыл бұрын

    Thanks!

  • @pashnyovv
    @pashnyovv2 жыл бұрын

    it's very interesting

  • @michaeleaster1815
    @michaeleaster18152 жыл бұрын

    1:23 Great video! To be fair, these comments drive the Reactive community crazy. They have questions/concerns about virtual threads, and the Java team have responses in return. As one brief example: if you use 1000s of virtual threads which call an external service, then this can swamp the external service. The Java team counters with "well, use semaphores to protect resources". That's fine, but illustrates there is more nuance here than at first glance.

  • @udadog

    @udadog

    2 жыл бұрын

    They also said that there are instances where you would want to use traditional threads. Would it not be better to just use a thread pool for the example you gave?

  • @michaeleaster1815

    @michaeleaster1815

    2 жыл бұрын

    @@udadog Ron Pressler (lead for Loom) has mentioned the semaphore idiom in his videos. I don't think one would want a platform thread, because if the task does other blocking operations (aside from call to external service), we would want that to be virtual. A platform thread would be overkill.

  • @thurstonn9210

    @thurstonn9210

    Жыл бұрын

    There is nothing in async/reactive programming that limits code from "overwhelming" an external service Virtual threads address a common desire, I want to get the better *efficiency* of using non-blocking IO (in reality, on sockets), without writing async-style (callbacks) code This has been available in Erlang like forever, and Go - the code looks sequential (i prefer that term to "blocking" or "synchronous"), but the runtime is using non-blocking IO under the covers Now, it's true that since it doesn't make sense to manage a pool of virtual threads, one of the side effects of a traditional thread pool is that it can serve to throttle demand (e.g. if a thread pool is designed to only execute code that consumes the external service), although of course this is not the purpose of a thread pool per se; now, if you want to throttle demand against an external service using virtual threads you will need some other mechanism (e.g. semaphores) The claim is pretty simple: if you want to : a. get the efficiency benefits of using non-blocking (socket) IO and b. write traditional sequential code (byte[] b = socket.read(2048)) you can do so in Java now using virtual threads this has been proven to work in other languages (look at the benchmarks for Erlang and Go TCP servers) for a long period of time The "Reactive community" had better get used to the idea that their java frameworks will face extinction (assuming the virtual thread implementation is stable and efficient); this is called progress

  • @mikasasakura644
    @mikasasakura6442 жыл бұрын

    Java 1.8, I love it, it is the source of my income.

  • @loic.bertrand
    @loic.bertrand2 жыл бұрын

    Very interesting! I like seeing the code, it helps a lot. Could we create JavaScript-like or Python-like generator functions using Continuations?

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

    Super....

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

    I love the cup.

  • @unbekannter_Nutzer
    @unbekannter_NutzerАй бұрын

    Thanks, very informative. :) Where do I find the fancy regular expressions from @12:20? (or: What would be reasonable?) Thanks.

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

    very informative video and he made it easy to understand this topic. loved this JEP Café series. BTW, from where we can buy this Java coffee cup? 🙂

  • @IvelinYanev
    @IvelinYanev2 жыл бұрын

    Hi Jose, Could you please share us a code example?

  • @user-gh8sg6vk4r
    @user-gh8sg6vk4r Жыл бұрын

    Is there anywhere I can get the live demo?

  • @FABGIO1
    @FABGIO12 жыл бұрын

    Hi! Great video really! Does intellij 2022.2 ea support jdk 19 already?

  • @FelipeGasparini
    @FelipeGasparini2 жыл бұрын

    How does Loom impacts some JIT performance optimizations like Escape Analysis? If I understood correctly, if Loom moves the stack to heap, EA doing stack allocations became not so useful, doesn't it? (but it is still very useful for hot-paths with non-blocking)

  • @sadiulhakim7814
    @sadiulhakim7814Ай бұрын

    Can i use Virtual Thread in all case? Is there any case where i cannot (should not) use Virtual Threads?

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

    Can you, please, tell me, if the implementation of Java virtual streams can compete with Erlang?

  • @richardnewton6586
    @richardnewton65862 жыл бұрын

    Do virtual threads support thread locals?

  • @JosePaumard

    @JosePaumard

    2 жыл бұрын

    They do. But you the prefered pattern is to use ExtentLocal.

  • @olivierboisse1678
    @olivierboisse167811 ай бұрын

    If you have a lot of virtual threads that yield at the same time (i.e. the stack is copied from the pthread to the heap), the heap memory might become overloaded isn't it ?

  • @igboman2860
    @igboman28602 жыл бұрын

    One of the problems with multithreading asides the cost of blocking is the risk of deadlocks, or livelocks as well as issues with shared memory thread safety. Does loom have an opinion around the paradigm for multithread like CSP

  • @tanveerhasan2382

    @tanveerhasan2382

    2 жыл бұрын

    What's CSP

  • @igboman2860

    @igboman2860

    2 жыл бұрын

    Communicating Sequential Processes (CSP)

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

    Wow! that Continuation is very useful, also the cpu probably has an 8 cores that's why there are only 9 platform thread.

  • @unbekannter_Nutzer

    @unbekannter_Nutzer

    Жыл бұрын

    At 12:40, you can read "12 cores".

  • @rafapiotrowicz6500
    @rafapiotrowicz65008 ай бұрын

    Its good approach to use virtual threads for multiple requests to database ? In particular thread will be call and mapping results (Its hard to split , because I use Spring Boot NamedParameterJdbcTemplate. Can you give me advice - I use Java 21 ?

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

    my God!!!!

  • @ZeBeaupre
    @ZeBeaupre2 жыл бұрын

    How do I access continuations? I added the OpenJDK 20 with loom, but I don't have access to jdk.internal where continuations are

  • @JosePaumard

    @JosePaumard

    2 жыл бұрын

    You need to add this when you compile and run your code: --enable-preview --add-exports java.base/jdk.internal.vm=ALL-UNNAMED. Do not do that in production though.

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

    Can someone elaborate the virtual thread getting pinned to a platform thread issue?

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

    Can you self host the tunnel server?

  • @wu013003
    @wu0130032 жыл бұрын

    where can I get that cup please?

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

    1:13 I started learning reactive programming yesterday and found it bit difficult to understand.

  • 2 жыл бұрын

    Please show us structured concurrency

  • @gsit80
    @gsit807 ай бұрын

    Source code reference would be good.

  • @premkumaru
    @premkumaru2 жыл бұрын

    So, memory is not a limiting factor on how threads I can instantiate... I was thinking it is one of the factors since stack takes memory... If we can instantiate 10Mill threads, at least memory is not a factor... Of course context switch by OS cannot be a cost as well since even virtual threads are doing their own context-switch by swapping over stacks... So, net net I am lost as to where the benefits are coming from... Is it OS process table size that limits max platform threads?.. Also, on a lighter note, I guess Java 1.2 (or 1.3) only had green threads. If my memory is right only starting 1.4 they mapped threads to actual OS threads. So, did we go back in capabilities and getting there again only now.. after what - i dont know - 20 years?

  • @guilhermealvessilveira8938

    @guilhermealvessilveira8938

    2 жыл бұрын

    No man. It's about not blocking kernel threads, when making IO calls.

  • @premkumaru

    @premkumaru

    2 жыл бұрын

    @@guilhermealvessilveira8938 Threads regardless whether they are virtual or real will block on IO. Is the process scheduling by JVM cheaper than what is being done by kernel?.. I want really understand where the benefits are coming from.

  • @guilhermealvessilveira8938

    @guilhermealvessilveira8938

    2 жыл бұрын

    @@premkumaru Well, they refactor the old IO to be non-blocking when you use virtual threads, it's looks like it's blocking, but it's not blocking. Wheh he say that it's blocking the virtual thread in the IO call, the virtual thread is suspended, but the kernel threads continue it's executions. Do you know event loop? It's almost the same, where the kernel threads check if the virtual thread block, if it's blocked, he get the next virtual thread. If you look deeply, you will see that the virtual thread is a data structure, where it has the context being executed, the stack and other necessary information, it's not the same as kernel thread, where it is scheduled by the operating system to execute. In the example above, you can have almost the same performance if you use the classic event loop, but it's hard to program using event loop, not so hard, but, it's hard to debug, because the execution don't look one after another, it's a mess to debug this kind of application. One of classicals non-blocking IO is the Java NIO ServerSocketChannel and SocketChannel with the Selector. But, with fiber threads, they hide that complexity, and in it's core is non-blocking, when executing bound IO (not when you execute CPU Bound, like matrix multiplication, any type of calculation). Sorry for the long text.

  • @premkumaru

    @premkumaru

    2 жыл бұрын

    @@guilhermealvessilveira8938 Hi, I started googling and it landed me in stack overflow... I find that biggest factors arre: 1. no need to enter and exit protected mode for context switches ... (makes tonne of sense to me as they are super expensive) 2. OSes cannot optimise for the target language. Some are saying the stack can be much smaller in green threads and can grow as needed. 3. OSes need to do lots of checks as access could be across processes 4. Some points about setup and teardown costs... but that is addressed using Thread pools. In fact it is cheap to create and destroy virtual threads. (may be this is the end of thread-pools) Yeah, block and ready state transitions need not go to kernel (need not cross protection level gates) regardless of whether it is IO or just sleep. Event driven or Async can be difficult to understand and develop. It breaks the flow. You cannot break the flow like say, initiate IO and setup a callback to run when it completes. This model is painful and clearly virtual threads arre helping us keep it as close to imperative... Thinking of my other point regarding green threads in 1.3, I remember those days even Linux did not have support for threads. I think Windows did. So, when java subsequently mapped Threads to OS/Platform threads, I guess it got a lot better in terms of performance. I guess may be for the first time they got pre-emptive! That's another interesting point: Are virtual threads pre-emptive?.. I don't think they. are. It would be nice to get a confirmation. Getting back, I think we got the best out of OS/Platform threads and we are all the way the other side and we are correcting back a bit. It is actually amazing to see this evolution.. (in a hurry now.. sorry about going all over.. will think through and post more if needed)

  • @premkumaru

    @premkumaru

    2 жыл бұрын

    Just wanted to add this.. did not use NIO much.. but I have used select() system call... to wait on multiple IO targets. This model ends up to be event driven and logic does not flow naturally.

  • @Unix404
    @Unix4042 жыл бұрын

    Baseeed

  • @olivierboisse1678
    @olivierboisse167811 ай бұрын

    Don't understand why you need to call thread.join() ? When a thread is not a deamon thread, it should prevent the jvm from exiting. Strangely, when I start a virtual thread without calling the join method, the jvm exit without waiting for the vthread to process its task.

  • @alexei3366
    @alexei33662 жыл бұрын

    Virtual Threads it's ... something like Coroutines in Kotlin?

  • @rajivkumar-ub6uj

    @rajivkumar-ub6uj

    2 жыл бұрын

    Yes

  • @JosePaumard

    @JosePaumard

    2 жыл бұрын

    Nope. Moving the stack to the heap is only in Loom.

  • @cya3mdirl158
    @cya3mdirl1582 жыл бұрын

    Loom has some drawbacks for instance these light threads are allocated on heap... ;(

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

    With unlimited ram lol

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

    I m get angry when watch this video, why not show all the code?

  • @Mistoffeleess
    @Mistoffeleess29 күн бұрын

    Oracle is only the reason why Java is losing its fame so rapidly despite these brilliant features. Look at this boring video! looks like it'd been recorded in the mid 90's. Who the hell uses daylight mode writing code in 2024!

  • @122mlb
    @122mlb11 ай бұрын

    Windows 🤮🤮

  • @redcrafterlppa303
    @redcrafterlppa3032 жыл бұрын

    3:52 It put a smile on my face to see my good old friend "Unsafe.getUnsafe()". It's enormous power and importants in fast library's is undeniable. Despite the fact that it's not meant to be used. It's powers simply cannot be expressed in Java concepts and classes because of it's unsafe nature. The unpredictable results if not used properly make it dangerous. My opinion : The only way to implement it's functionality into java without being unsafe is to give up. Java should go the rust way and say "here you can have that dangerous tool. But it's your responsibility to use it correctly.". By giving the dangerous operation a keyword and a block / function you can contain the dangers in a concise space and discouraging people from writing simple wrapper to access the dangerous functions in an uncontrolled pseudo safe way.

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

    OpenJDK 19.0.1, the 100 000 virtual threads consume ~100MB memory (profiler shows 100MB for jdk.internal.vm.StackChunk). Anybody knows why? Is Loom not ready, I thought it's supposed to consume very little memory? Now it consumes even more than platform threads.

  • @sadiulhakim7814
    @sadiulhakim7814Ай бұрын

    Look at this amazing community, Java Community.

Келесі