Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Won't Fix
-
None
-
None
-
None
-
None
-
Unknown
Description
When using virtual threads, it's important to avoid the use of synchronized objects and methods because I/O operations executed in them will pin the virtual thread to its carrier thread, blocking the carrier thread instead of the virtual one.
Executing some tests with a CXF client in a Tomcat server using virtual threads I see that, if I spawn a few tens of virtual threads I get a lot of thread pinning due to the code in
PhaseInterceptorChain
In this class, there's a method that's invoked for all requests
public synchronized boolean doIntercept(Message message)
This method pins the virtual thread to the carrier thread for all the duration of the request and response, which might be a lot of time and it hinders the multithreaded applications throughput. Just changing the use of synchronized keywords for ReentrantLocks will solve this issue.