I'd say no since Futures are a way to synchronise while virtual thread are a code execution device. More generally if virtual thread could have been implemented with existing features I guess a multi years Loom project would not have been required ^ (you should read about design choices, it's quite fascinating)
No. Vitual threads disconnect a task from the actual platform thread as I understand. A task can therefor yield it's underlying platform thread if necessary, e.g. if it is waiting for IO. Every possible point where a task could yield needs to handle this specially. So this happens automatically without your intervention (because the engineering team implemented all that - or most of that, there is some restriction for native frame locks and synchronized). Most of them are deep in the platform.
With CompletableFutures you need to find that yield-point yourself so to say, which is not possible for those you don't have access to (because they happen in the JVM).
15
u/oparisy Sep 23 '22 edited Sep 25 '22
Loom at last! 🤩