Dear Project Lombok Developers,
I am writing to propose an enhancement to Project Lombok that I believe would benefit many Java developers who work with concurrent programming, particularly those using the latest Java 21 Virtual Threads.
In Java 21, the introduction of virtual threads docs.oracle.com provides a lightweight, efficient alternative to traditional OS threads. While this is an exciting development, it presents some challenges when using the synchronized keyword for thread safety, especially in high load systems.
The java.util.concurrent.ReentrantLock class provides an alternative to the synchronized keyword that offers more flexibility and can work better with virtual threads. However, using ReentrantLock can make the code more verbose compared to using the synchronized keyword.
Project Lombok's @Synchronized annotation has been incredibly useful in reducing boilerplate code related to synchronized methods or blocks. I would like to propose the addition of a new annotation, perhaps named @Lock, that would function similarly to @Synchronized, but use ReentrantLock under the hood. This would help developers leverage the benefits of ReentrantLock and virtual threads without adding verbosity to their code.
Here's an example of how such an annotation might be used:
public class SharedObject {
@Lock
public void perform (){
// Critical section - using j.u.c.Lock - here
}
}
The @Lock annotation would handle the lock acquisition and release, similar to how @Synchronized handles synchronized blocks or methods.
Thank you for considering this proposal. I believe that the addition of this feature would greatly enhance Project Lombok and provide significant benefits to the Java developer community.
Best regards,
Andrej
Dear Project Lombok Developers,
I am writing to propose an enhancement to Project Lombok that I believe would benefit many Java developers who work with concurrent programming, particularly those using the latest Java 21 Virtual Threads.
In Java 21, the introduction of virtual threads docs.oracle.com provides a lightweight, efficient alternative to traditional OS threads. While this is an exciting development, it presents some challenges when using the
synchronizedkeyword for thread safety, especially in high load systems.The
java.util.concurrent.ReentrantLockclass provides an alternative to thesynchronizedkeyword that offers more flexibility and can work better with virtual threads. However, usingReentrantLockcan make the code more verbose compared to using thesynchronizedkeyword.Project Lombok's
@Synchronizedannotation has been incredibly useful in reducing boilerplate code related to synchronized methods or blocks. I would like to propose the addition of a new annotation, perhaps named@Lock, that would function similarly to@Synchronized, but useReentrantLockunder the hood. This would help developers leverage the benefits ofReentrantLockand virtual threads without adding verbosity to their code.Here's an example of how such an annotation might be used:
The
@Lockannotation would handle the lock acquisition and release, similar to how@Synchronizedhandles synchronized blocks or methods.Thank you for considering this proposal. I believe that the addition of this feature would greatly enhance Project Lombok and provide significant benefits to the Java developer community.
Best regards,
Andrej