Sync, Async, Blocking and Non-Blocking | Rock the JVM

Поділитися
Вставка
  • Опубліковано 30 тра 2024
  • Written form to keep for later: blog.rockthejvm.com/sync,-asy...
    Using the controllable Futures pattern: • How to Write Controlla...
    This video is for programmers of all levels (although I write Scala, naturally). We discuss how some computations are synchronous and blocking, async and blocking, and how we could achieve async non-blocking computations with Akka actors.
    Async and non-blocking is what you want. However, even that has its drawbacks. So at the end I show how you can also obtain meaningful values out of a non-blocking computation.
    Follow Rock the JVM on:
    LinkedIn: / rockthejvm
    Twitter: / rockthejvm
    Blog: rockthejvm.com/blog
    -------------------------------------------------------------------------
    Home: rockthejvm.com
    -------------------------------------------------------------------------
    ///////////////////////////////////////////////
    // Libraries code for build.sbt:
    val akkaVersion = "2.6.4"
    libraryDependencies ++= Seq(
    // akka streams
    "com.typesafe.akka" %% "akka-actor-typed" % akkaVersion
    )
    ///////////////////////////////////////////////
    Timeline:
    0:00 intro & requirements
    0:47 synchronous, blocking
    2:48 asynchronous, blocking
    6:20 asynchronous, non-blocking with an actor
    11:17 obtaining meaningful values
  • Наука та технологія

КОМЕНТАРІ • 32

  • @mourikogoro9709
    @mourikogoro9709 3 роки тому +7

    6:38 "Actor ... is not something active. It's just a data structure."
    This enlightened me. Brilliant tutorial!

  • @cody8708
    @cody8708 3 роки тому +3

    Wow.. I read multiple articles without it clicking. I watched your video and felt like I understood it well before it was even over. Thanks a bunch, you're an awesome instructor

  • @Krazness
    @Krazness 11 місяців тому

    Thanks for these great videos. Do you have any resources on writing and debugging Futures with the ScalaTest framework? I've been trying to use IntelliJ's debugger and evaluate tool to follow the code paths. But I'm not getting through

  • @mingHiewNN
    @mingHiewNN 3 роки тому +5

    Thank you for the fantastic work, Daniel! Btw, I'm just wondering if you have any plan to do a course on the akka typed actor and make it available on Udemy or RockTheJVM, as I'm really looking forward to it

    • @rockthejvm
      @rockthejvm  3 роки тому +3

      On the roadmap - it will take some time as the material is massive, so thanks for the patience!

  • @yannikschroder3381
    @yannikschroder3381 3 роки тому +3

    Awesome video!
    One thing that i dont understand is if u take the example of making a HTTP request or call to a database.
    I understand that if this call is made asynchronous, the calling thread can continue working, but the Thread waiting for the Future to complete is blocked.
    However, if you do this with Actors, the fact doesn't change that by the nature of the HTTP request or database it will take some time to complete the result, so it still blocks the execution
    somewhere, right?

    • @rockthejvm
      @rockthejvm  3 роки тому +1

      We're concerned with whether the thread itself is waiting. If you fire the call and the thread moves to other tasks, it's not blocked.

    • @francis.joseph
      @francis.joseph 2 роки тому

      this is not getting

  • @victorpre
    @victorpre Рік тому +1

    another great video

  • @unimatrixz3ro226
    @unimatrixz3ro226 2 роки тому

    It's an amazing video, thanks :)

  • @waagnermann
    @waagnermann 3 роки тому +2

    in the last line you call asyncNonBlockingResult.onComplete(...) which will be executed in one of the global execution context’s threads.
    question: how this thread will know about the future completion (which will be completed in the actor’s dispatcher’s thread pool)?
    will the dispatcher’s thread somehow notify the globals’s thread that future is completed and is ready to be used in onCompleted(..) block?

    • @rockthejvm
      @rockthejvm  3 роки тому

      Something like that. The execution context also has a small scheduler which is able to run callbacks and Future transformations like map/flatMap.

  • @georgezorikov3075
    @georgezorikov3075 3 роки тому +1

    Good video, thank you!
    One question, if you allow me. Let's say we have 1 processor, 1 core machine. Will Futures and Asyncs run concurrently, I mean, 1 thread jumps back and forth from one task to another, imitating concurrency, or will it be sequential operations with a fully determined order?

    • @rockthejvm
      @rockthejvm  3 роки тому +1

      Nope, still concurrent. The OS can schedule and interrupt threads on the same physical core at (almost) any time, so the same conditions for multithreading still apply.

  • @jurevreca9229
    @jurevreca9229 Рік тому

    Thank you for this great tutorial. Could you please explain the syntax at 7.45. Specifically the syntax that confuses is me is the "someMessage=> {the function block}". As far as I understand the "=>" operator is used to define types. I.e. you can define the type definition of a function. So what does this syntax mean?

    • @rockthejvm
      @rockthejvm  Рік тому +1

      Check the Scala at Light Speed video that talks about functions, we have everything there.

  • @Gohel95
    @Gohel95 3 роки тому +1

    Thanks💕💕💕

  • @mr_kurro
    @mr_kurro 3 роки тому +1

    I am a big fan of your courses on RTJVM. I have a question: “Using actor is asynchronous and non-blocking”, in short, the idea is delegating “blocking thing” to actor’s dispatcher and benefit from its better scheduling, isn’t it?

    • @rockthejvm
      @rockthejvm  3 роки тому +1

      You're not delegating anything to an actor - you're just sending it a message. The internal logic of the actor will run at some point, on some thread. The end goal is not necessarily better thread scheduling (although that is also true) but better isolation of logic in your application, without needing to care about threads at all.

  • @sergeikharchikov1157
    @sergeikharchikov1157 3 роки тому +2

    Thank you, pretty nice like always. Do you have any plans to do a course about ZIO ?

    • @rockthejvm
      @rockthejvm  3 роки тому +1

      Perhaps - shout in the comments if anyone else needs ZIO!

    • @shef9192
      @shef9192 3 роки тому

      Zio +

    • @nullptr7
      @nullptr7 3 роки тому

      Yes zio would be great 🔥

  • @waagnermann
    @waagnermann 3 роки тому +2

    Do you think you made non-blocking operation just because you have removed from the third case "Thread.sleep(10000)" line which occured in first two cases? If I put this line to the code-block that will be executed by ActorSystem then there`ll be also a blocking. The only difference is that this blocking will block the dispatcher`s thread, but since dispatcher, global execution context and a main thread are placed on the same machine - then what`s the profit of the model (with promises) that you`ve shown?))))))))

    • @rockthejvm
      @rockthejvm  3 роки тому

      The sleeps are just for illustration, I think you got the idea.

  • @ketanpurohit9086
    @ketanpurohit9086 2 роки тому +1

    Very good lesson - interested in finding out why the application does not terminate. Is there some event-loop running?.. if so is there a 'stop' method.
    Edit: The actor systems have to be terminated. rootActor.terminate() and promiseResolver.terminte()

    • @rockthejvm
      @rockthejvm  2 роки тому

      There's the execution context running, which needs stopping.

  • @sathisg
    @sathisg 3 роки тому

    Will the main thread not block if message is being sent to Remote actors mail box?

    • @rockthejvm
      @rockthejvm  3 роки тому

      Never - message sending is fully non-blocking

  • @coffeezealot8535
    @coffeezealot8535 4 роки тому +1

    haha nice parrot