Skip to content
This repository was archived by the owner on Jan 9, 2025. It is now read-only.
This repository was archived by the owner on Jan 9, 2025. It is now read-only.

Java 21 virtual threads issue #625

@hrstoyanov

Description

@hrstoyanov

Is your feature request related to a problem? Please describe.

The upcoming release of Java 21 will make virtual threads an official feature. And I hope the Microstream team plans to take full advantage of virtual threads! I was looking at the source code for ObjectCopier, and noticed that the SYNCHRONIZED java keyword is used (maybe in other places as well). The problem is that synchronized does not work well with virtual threads. This is explained here (but is a widely know issue you can google for):
https://blog.fastthread.io/2023/02/28/pitfalls-to-avoid-when-switching-to-virtual-threads/

Describe the solution you'd like

Use java ReentrantLock instead:

class MyClass{
   private final ReentrantLock lock = new ReentrantLock();
   // ...

   public void myMethod() {
     lock.lock();  // block until condition holds
     try {
       // ... method body
     } finally {
       lock.unlock();
     }
   }
 }

yes, the code is less pretty, but the price is worth it....This should work fine with older Java versions as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions