Can someone explain how virtual threads fit in with something like a Swing/JavaFx app? You still off load any long running work to a fork join pool and invoke back when you are done?
What about messaging libraries that have threads that call into your code? It has to be virtual threads all the way though right?
Hmm, good point! It made me thinking. I obviously can't say that there are no good fits on the desktop for this but I feel like even the most IO bound desktop apps will still only create tasks in the thousands at most. Do you have any examples, you've likely been thinking a lot more about this than I (but maybe desktop hasn't been on your radar?).
I'm just struggling to come up with a use case where a desktop application would want to do even thousands of things at the same time. Even if each repaint was its own task, each mouse/keyboard event was its own task and each connection to a database, server and each read from disk was its own task a user wouldn't be able to spawn this much work. It needs to be some automated IO bound tasks, and such work is the reason we call a server instead.
A server needs to handle millions of tasks because they may have millions of users to serve. A desktop has one user to serve.
But maybe I'm just not imaginative enough.
The structured concurrency parts of Loom looks as it could be very relevant for desktop though. A safer way to get off the EDT without introducing bugs looks really interesting.
9
u/cantstopthemoonlight Aug 02 '22
Can someone explain how virtual threads fit in with something like a Swing/JavaFx app? You still off load any long running work to a fork join pool and invoke back when you are done?
What about messaging libraries that have threads that call into your code? It has to be virtual threads all the way though right?