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

Increase Java 21 virtual thread performance via get rid of synchronized #2032

Open
asmburning opened this issue May 17, 2024 · 1 comment
Open
Assignees
Labels
api: pubsub Issues related to the googleapis/java-pubsub API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@asmburning
Copy link

What the problem is : Java 21 virtual thread might hinder its scalability when using synchronized

Based on Java doc Java 21 virtual thread
A virtual thread cannot be unmounted during blocking operations when it is pinned to its carrier. A virtual thread is pinned in the following situations:

  1. The virtual thread runs code inside a synchronized block or method
  2. The virtual thread runs a native method or a foreign function (see [Foreign Function and Memory API]

Pinning does not make an application incorrect, but it might hinder its scalability.
Try avoiding frequent and long-lived pinning by revising synchronized blocks or methods that run frequently and guarding potentially long I/O operations with java.util.concurrent.locks.ReentrantLock.

Describe the solution you'd like

Use java.util.concurrent.locks.ReentrantLock instead of synchronized

@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/java-pubsub API. label May 17, 2024
@michaelpri10
Copy link
Contributor

To make this change, we would need to ensure that we don't cause any compatibility issues or degraded performance for any Java versions. Marking this as a feature request.

@michaelpri10 michaelpri10 added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/java-pubsub API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

2 participants