Trying JDK21 Structured Concurrency from Clojure

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 ม.ค. 2025

ความคิดเห็น • 9

  • @andrey.fadeev
    @andrey.fadeev  หลายเดือนก่อน +1

    ☕ If you liked this video and want to support my channel, please consider buying me a coffee. Your contribution helps me create more content like this:
    👉 Buy Me a Coffee: www.buymeacoffee.com/andrey.fadeev
    👉 Ko-fi: ko-fi.com/andreyfadeev
    Please also subscribe to my other resources:
    👉 Substack: blog.andreyfadeev.com
    👉 Telegram: t.me/andreyfadeevchannel
    I'm truly grateful for your support, and thank you for watching! 🙏

  • @EvgenyPakhomov
    @EvgenyPakhomov หลายเดือนก่อน +1

    How exactly are the other threads terminated? Would, say, a plain infinite loop also be somehow interrupted if it's running in a virtual thread - something that wouldn't happen in a regular thread?

    • @andrey.fadeev
      @andrey.fadeev  หลายเดือนก่อน +1

      I don't think it happens really, a virtual thread with with `while true println` never exists even if the other thread finished with exception and the on failure policy :(
      So it still needs interruptible points in the cycle, eg sleep

  • @sfyire
    @sfyire หลายเดือนก่อน +1

    Does it matter if your task is IO bound Vs CPU bound?

    • @ales-rocks
      @ales-rocks หลายเดือนก่อน +1

      It kinda does. Vthreads generally won't help you with CPU bound tasks. For that I'd still prefer fixed threadpool of platform threads or similar and let OS scheduler to control the preemption.

    • @ales-rocks
      @ales-rocks หลายเดือนก่อน +1

      Probably the best way to look at the issue is, that vthreads are cheap to block (that means, cheap to wait for something to happen) and it's where they shine.

    • @andrey.fadeev
      @andrey.fadeev  หลายเดือนก่อน

      yeap that's it :)

    • @bobbycrosby9765
      @bobbycrosby9765 หลายเดือนก่อน +1

      A virtual thread that does no blocking will never be interrupted. This is "optimal" but not always desired behavior - optimal in the sense that it is probably the most performant, not always desired because sometimes you want responsiveness over throughput.
      If you want to give a chance for other virtual threads to perform work a workaround is to call Thread.sleep. For some reason they didn't decide to let Thread.yield() to do this, which would be a great improvement.

    • @softwarestory
      @softwarestory หลายเดือนก่อน

      @@bobbycrosby9765 you can also call (Thread/.isInterrupted (Thread/currentThread))