Skip to content
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

Java 21 virtual threads issue #625

Open
hrstoyanov opened this issue Aug 6, 2023 · 7 comments
Open

Java 21 virtual threads issue #625

hrstoyanov opened this issue Aug 6, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@hrstoyanov
Copy link

hrstoyanov commented Aug 6, 2023

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.

@hrstoyanov hrstoyanov closed this as not planned Won't fix, can't repro, duplicate, stale Aug 10, 2023
@hrstoyanov hrstoyanov reopened this Aug 14, 2023
@hg-ms
Copy link
Contributor

hg-ms commented Aug 16, 2023

Many thanks for your proposal.
We must carefully check if the described problem can’t occur at another part of the involved code if we implement the proposed improvement.

@hg-ms hg-ms added the enhancement New feature or request label Aug 16, 2023
@hrstoyanov
Copy link
Author

hrstoyanov commented Aug 16, 2023

Thanks for considering my proposal! This change should be backward compatible. Btw, I noticed that in the Bookstore demo you already have an elegant utility class to do Reentrant locks, you may just utilize it in the core codebase.

@guykatz
Copy link

guykatz commented Sep 11, 2023

@hrstoyanov @hg-ms we are also moving to J21 soon after its release. we have been waiting for V threads for some time now as it fits our model of work nicely. we will move from many pool executor to the new V threads executor.
this means I will have virtual threads running and accessing microstream all the time.
if there is an issue I believe this should be examined asap and notify MS users that v thread will not work properly with MS.
thanks everyone for pointing this out!

@hrstoyanov
Copy link
Author

@guykatz - Thanks!
One thing that I was not aware of, is that you guys try to keep Microstream compatible with Android Java, which is lacking and slow to catch up (if at all in future, given the Google policy towards Java, Oracle lawsuits, etc ).

In the below issue, I suggested that you will end up forking the codebase sooner or later for that reason. So, if you are going to move forward with Java 21 virtual threads, I presume you will fork the codebase, then maybe the below issue can also be re-considered.

#627

@guykatz
Copy link

guykatz commented Sep 11, 2023

@hrstoyanov I am not a microstream commiter. When I say we I meant the company I am employed in :)
I am in the same boat as you r :)

@useryq8
Copy link

useryq8 commented Jan 23, 2024

@hg-ms @fh-ms , hello, another related question, Could microstream 8.0.1 work with java 21 when tomcat uses virtual thread and some http thread will write data to microstream? I plan to upgrade my java to 21 for performance ,but I used microstream 08.01.00-MS-GA, the data is very important for me, so we need to know whether microstream 8.0.1 work with java 21 or not. thank you very much!

@hrstoyanov
Copy link
Author

@useryq8 there should be no problem upgrading to Java 21.

Incidentally, there is a pending merge request to integrate Eclipse Store 1.1.0 (when released - maybe in 2 weeks or so) into Helidon 4.x. If you chose to migrate from Microstream to Eclipse Store, you will find an Eclipse store migration utility for converting your Microstream data files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants