Avoiding virtual thread pinning by moving the code to run on a platform thread
I am migrating my Spring Boot application to virtual threads from the platform ones.
Generally it works fine, no pinning happens. But for some request there could be an operation that leads to the pinning (due to a blocking operation inside of a synchronized block) and I want to avoid that. If I don’t, I could not end up in a situation in which all the carriers are pinned and there’s no platform thread to serve a request left.
The operation that leads to the pinning is a part of a 3rd-party library. While waiting for the fix that would allow to execute the library’s code without pinning, I am planning to use the following approach: