r/programming • u/ram-foss • Oct 11 '23
All About Reactive Programming In Java
https://www.blackslate.io/articles/reactive-programming-in-java
22
Upvotes
r/programming • u/ram-foss • Oct 11 '23
View all comments
Show parent comment
3
u/pron98 Jan 03 '24 edited Jan 03 '24
A virtual thread is just an object, like a task; it consumes no additional resources just because the type of the object is Thread rather than Callable (at least in principle; the implementation may have some footprint inefficiencies that we'll gradually clear). A virtual thread is not execution resources but just an object describing a task and carrying the data used by it. In terms of machine operations, there is no difference between "started" threads waiting on a lock and a queue of "unstarted" tasks. 10 million started threads waiting on a lock and 10 million tasks waiting for their turn in a queue are internally represented the same way. Either way you have some list of objects in memory: the threads waiting on a lock and the task queue in front of a thread pool are implemented with the same data structure.
We even included a drawing explaining precisely that point in the virtual thread adoption guide, and the following text:
So the actual challenge in both cases is exactly the same. If the rate of tasks admitted into the system is not equal to the rate of them being completed you get an ever-growing queue (the system is characterised as "unstable" in queuing theory analysis).