Skip to content

Add fair lock policy to @Locked via @Locked.Policy - #4063

Open
vulinh64 wants to merge 1 commit into
projectlombok:masterfrom
vulinh64:master
Open

Add fair lock policy to @Locked via @Locked.Policy#4063
vulinh64 wants to merge 1 commit into
projectlombok:masterfrom
vulinh64:master

Conversation

@vulinh64

@vulinh64 vulinh64 commented Aug 8, 2026

Copy link
Copy Markdown

Hi Lombok team,

This is my first contribution, and thank you for taking the time to review it.

This PR adds class-level lock fairness configuration through:

@Locked.Policy(fairness = true)

When present, Lombok generates fair locks for the class:

  • @Locked -> new ReentrantLock(true)
  • @Locked.Read / @Locked.Write -> a shared new ReentrantReadWriteLock(true)

By default, ReentrantLock and ReentrantReadWriteLock are non-fair, and Lombok’s existing behavior remains unchanged. The policy only affects locks generated by Lombok; explicitly named locks and user-declared lock fields are deliberately left untouched.

With JDK 25 that fixed the pinned synchronized issue, the usage of @Locked can still be attractive with the optional fairness policy.

The implementation includes javac and Eclipse support, transform tests for generated and named locks, and documentation/usage-example updates.

I would appreciate feedback on the API and implementation choices.

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.

1 participant