Return to site

๐Ÿงต blocking vs non-blocking

January 28, 2024

In this talk, Bazlur Rahman gives intel on virtual threads that empower thread concurrency (you can run millions on thread now).

virtual threads diagram

banking teller analogy

  • A teller ๐Ÿ‘จ is like a platform thread ๐Ÿงต because they can only process one customer ๐Ÿ‘ฑ at a time.
  • A customer ๐Ÿ‘ฑ is like a task โœ… that the thread needs to perform.
  • Sometimes, a customer ๐Ÿ‘ฑ or a task may need some external information or resources ๐Ÿ’พ before it can be completed. This is called a blocking operation ๐Ÿ›‘ because it blocks the teller ๐Ÿ‘จ [or the platform thread ๐Ÿงต] from doing anything else until it is resolved.
  • The teller ๐Ÿ‘จ [or the platform thread ๐Ÿงต] can park the customer ๐Ÿ‘ฑ or the task that is blocked, and move on to the next one in line. This means that the customer ๐Ÿ‘ฑ or the task is temporarily suspended โธ๏ธ, and will resume โ–ถ๏ธ when the blocking operation is resolved. This is called a parked virtual thread because it is a virtual thread that is parked by the platform thread ๐Ÿงต.
  • By parking the customer ๐Ÿ‘ฑ or the task, the teller ๐Ÿ‘จ [or the platform thread ๐Ÿงต] can process more customers or tasks at the same time, and increase the concurrency. Concurrency is the ability to run multiple tasks at the same time or in parallel.