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

Avoid synchronized during blocking operations (loom friendliness) #97

Open
ravi-signal opened this issue Jan 17, 2024 · 0 comments
Open

Comments

@ravi-signal
Copy link

Virtual threads, introduced in JEP 444, are forced to pin to their carrier threads when in a synchronized block. Since AmazonDynamoDBLockClient synchronizes on LockItems while performing blocking dynamodb operations, using the lock client from a virtual thread pins the virtual thread to the carrier thread while waiting for the operation to complete (which sort of defeats the purpose of virtual threads).

JEP 444 suggests replacing synchronzied blocks that contain long blocking I/O operations with ReentrantLock

avoid frequent and long-lived pinning by revising synchronized blocks or methods that run frequently and guard potentially long I/O operations to use java.util.concurrent.locks.ReentrantLock instead.

I'd be happy to open a PR if you're amenable to tossing a ReentrantLock in LockItem to replace the synchronized blocks

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

No branches or pull requests

1 participant