New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Virtual Threads - JDK21 #2710
Comments
This is extremely helpful of you to share with us, @mjagus! Was the only spot you faced issues with this on using Virtual Threads? Do note that I do not think we are dealing with a bug here, if I am honest with you. |
Hi Steven, I also briefly looked at framework's source code to see if there are any obvious code patterns that may lead to thread pinning and I noticed
Since event handlers are allowed to do I/O, this code will most likely cause the virtual thread executing this code to be pinned. |
Thanks for taking another look, @mjagus; your effort is much appreciated. |
Minor update on this issue, mainly concerning the milestone.
"Desire" one will be covered in release 4.9.0, but desire two cannot. With the above, I think it's clear why I'll remove this issue from milestone 4.9.0. |
Basic information
--enable-preview
switchI've been experimenting recently with project Loom by replacing various thread pools with virtual thread executors and running my application with
-Djdk.tracePinnedThreads=full
JVM option. The stack trace below popped up after I replaced my Quartz scheduler thread pool and QuartzDeadlineManager triggered my saga's@DeadlineHandler
method:The thread pinning happens because of synchronized block in
ConcurrentHashMap.computeIfAbsent
method. That block wraps a call to mapping function which happens to do I/O when underlyingSagaStore
implementation is anything different thanInMemorySagaStore
(in my case it is JpaSagaStore).At first this may look like something that should be reported to OpenJDK guys, but after quick skimming of JDK's mailing list it turns out that they are aware of this, but the fix is nowhere near close (according to Doug Lee himself), so it might be worthwhile to fix it in the framework itself before Loom goes GA (which happens in a few months apparently). The obvious solution would be to replace
ConcurrentHashMap
withHashMap
+ReadWriteLock
combo.Expected behaviour
Virtual thread is not pinned to carrier thread when a saga is first loaded into
managedSagas
map inAnnotatedSagaRepository
.Actual behaviour
Virtual thread is pinned, which might lead to a potential deadlock in the JVM when all carrier threads become blocked.
The text was updated successfully, but these errors were encountered: