Skip to content

Replace synchronized with ReentrantLock #984

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

Merged
merged 4 commits into from
Jul 27, 2022
Merged

Conversation

jyemin
Copy link
Collaborator

@jyemin jyemin commented Jul 25, 2022

In order to get the benefit for structured concurrency, the driver
must use Lock#lockInterruptibly rather than simply Lock#lock.

JAVA-4642

What use of synchronized is left out of this PR?

  • Used in the bson module: I didn't include this because MongoInterruptedException is in driver-core, not bson, so it wasn't clear what exception should be thrown. So deferring this for now
  • Use in driver-legacy. Generally we don't make improvements in legacy
  • Use in threads that the driver starts itself. This can be done later if we ever move these to virtual threads. But also, these threads are not accessible to applications so can't easily be interrupted.
  • Use in asynchronous contexts. Structured concurrency wouldn't be used with reactive streams, so it's not needed
  • Use in tests. Obviously these are ignorable

@jyemin jyemin requested review from rozza and katcharov July 25, 2022 19:53
@jyemin jyemin self-assigned this Jul 25, 2022
In order to get the benefit for structured concurrency, the driver
must use Lock#lockInterruptibly rather than simply Lock#lock.

JAVA-4642
Copy link
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - one DRY and naming improvement suggestion.

@jyemin jyemin requested a review from rozza July 26, 2022 14:22
Copy link
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jyemin
Copy link
Collaborator Author

jyemin commented Jul 26, 2022

Updated GridFS as well

@jyemin jyemin requested a review from rozza July 26, 2022 16:31
Copy link
Collaborator

@katcharov katcharov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jyemin jyemin merged commit 3ef3747 into mongodb:master Jul 27, 2022
@jyemin jyemin deleted the j4642 branch July 27, 2022 11:59
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

Successfully merging this pull request may close these issues.

3 participants