▲ | xmcqdpt2 3 days ago | ||||||||||||||||
We've been looking at virtual threads in a project at work and what we found is that it is quite difficult to adapt existing code to run with virtual threads. For example, class initialization pins a thread so any singleton defined in the standard, recommended Java way (using a static inner instance of an inner class) can hang your program forever if the singleton definition suspends. And because they worked really hard on making async colourless, there is no way to know that a method call will suspend. This is a known issue with a workaround if the suspend is due to a network call, https://bugs.openjdk.org/browse/JDK-8355036 which is useful for some applications (web servers). Figuring out that this is why my program was hanging required quite a bit of work too. We are still frustratingly far from the ergonomics of Go concurrency (all threads are virtual threads, hangs automatically panic). | |||||||||||||||||
▲ | puredanger 3 days ago | parent | next [-] | ||||||||||||||||
Clojure's focus on immutable data and pure functions side-step a lot of the trickiest issues with virtual threads. It's often not hard to isolate the I/O parts of your program into flow processes at the edges that can be mapped to the :io pool using virtual threads. | |||||||||||||||||
| |||||||||||||||||
▲ | gf000 3 days ago | parent | prev [-] | ||||||||||||||||
> can hang your program forever if the singleton definition suspends I am no expert on the topic, but this seems like a very edge case scenario, that is not trivial to reproduce on even the linked bug ticket. Do you think it really is that big of an issue? | |||||||||||||||||
|