Java Virtual Threads - How Virtual Threads Work, Scheduling, Cooperation and More

Поделиться
HTML-код
  • Опубликовано: 23 ноя 2024

Комментарии • 20

  • @MadeEasyTech
    @MadeEasyTech Год назад +2

    It was great explanation about virtual threads.

  • @lemonadeintech
    @lemonadeintech Год назад +1

    This is a great primer!

  • @bobyrasta100
    @bobyrasta100 Год назад

    This is really advances stuff. Do you intent to do a video that starts from Threads basics walking right up to advanced stuff like this?

  • @re1konn
    @re1konn Год назад +5

    I feel bad for making 42 views into 43. Did I just change the meaningOfLife?

    • @re1konn
      @re1konn Год назад +1

      oh my bad, it's immutable :p

  • @utishrajkarnikar9612
    @utishrajkarnikar9612 9 месяцев назад +1

    Awwwesome 🎉

  • @leorandomnickname
    @leorandomnickname Год назад

    probably a dumb question but... when you submit something to a pool of threads like a ForkJoinPool, you are actually creating a "Task" which is going to be queued and handled by a thread when available, so in practice I don't see any advantage of using virtual threads since the "task" should be already lightweight, and the blocking should be also semantic, you don't block the thread of a pool, you just block a task. So long I don't use Java that when you wrote "var" I thought you were confusing Scala with Java xD
    update: now I saw that you showed that virtual threads are implemented with a fork join pool o_O
    so anything that can be implemented with virtual threads can be imlemented with a fork join pool with essentially the same behaviour and semantics in older version of java... is that correct.

    • @rockthejvm
      @rockthejvm  Год назад +5

      It's not just the fork-join pool, it's the main Thread API that is now lightweight. This is subtle, but game-changing: for example, you can use blocking calls with the main Thread API (which used to be bad practice) and it's totally fine.

    • @levinie5081
      @levinie5081 Год назад

      Jvm will unload task(virtual thread) when it meet some blocking call (not all kinds are supported currently e.g. sychronized block), while in the past, those blocking calls would block the theads of thread pool

    • @davidparker5530
      @davidparker5530 Год назад +1

      It's because your assumption: ""task" should be already lightweight, and the blocking should be also semantic, you don't block the thread of a pool, you just block a task" is wrong. If you make an I/O call to a socket on a task for example, it WILL block the thread in your pool. Before Virtual Threads the only way to leverage non-blocking IO (i.e. those based on epoll, kqueue, iocp) was to leverage java.nio, and good luck with that. A "task" in Java is not the same conceptually as an async Task in C# or Swift or a promise in Javascript, all of which have non-blocking implementations. But with virtual threads we have that now!

  • @tak68tak
    @tak68tak Год назад

    is Go and Rust Tokio channel equivalent available in Java VT?

    • @rockthejvm
      @rockthejvm  Год назад

      Not quite - different mental model

  • @dangalimov7435
    @dangalimov7435 Год назад

    Will there be a spring boot course? (it would be really interesting in the form of a full-fledged project with ui)

  • @scalacode
    @scalacode Год назад

    I think it is the same as a green thread/fiber in Cat Effects?

    • @rockthejvm
      @rockthejvm  Год назад +2

      The goal and mechanics are similar, the API/thinking model is a bit different.

  • @krellin
    @krellin 7 месяцев назад

    this is not how it works this is "how to use it"...
    how it works would be : how does virtual thread carry around the stack, how does it work under the hood, how it identifies what is "blocking" etc etc...

  • @deadvatniks
    @deadvatniks Год назад +1

    I recon the point of having virtual threads is to not have a pool of them. You rather create a new VT for each task.

    • @владимирсенцов-р1ю
      @владимирсенцов-р1ю 9 месяцев назад

      Not only. It looks like Kotlin coroutine and suspend function but now it is managed by JVM not Kotlin compiler.