|
|
|
|
|
by xmcqdpt2
305 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). |
|