r/java • • Aug 02 '22

Bright future to Java devs ahead 🚀

https://www.youtube.com/watch?v=2nOj8MKHvmw
188 Upvotes

27 comments sorted by

View all comments

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?

3

u/nioh2_noob Aug 03 '22

I actually see no real benefits with JavaFX in moving my current background threads into the new virtual ones.

8

u/veraxAlea Aug 03 '22

Yeah, desktop apps typically don't spawn hundreds of thousands of background threads.

6

u/pron98 Aug 03 '22

Virtual threads do not replace platform threads; they replace tasks. So the relevant question is, do desktop apps typically spawn many tasks?

1

u/veraxAlea Aug 04 '22

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.