diff --git a/website/templates/features/experimental/Locked.html b/website/templates/features/experimental/Locked.html new file mode 100644 index 00000000..cd4f599c --- /dev/null +++ b/website/templates/features/experimental/Locked.html @@ -0,0 +1,45 @@ +<#import "../_features.html" as f> + +<@f.scaffold title="@Locked" logline="TODO"> + <@f.history> +

+ @Locked was introduced as an experimental feature in lombok v1.18.21. +

+ + + <@f.experimental> + + Current status: unknown + + + <@f.overview> +

+ @Locked is an alternative to @Synchronized that uses Java locks for more extensive locking operations. The annotation locks on the provided field if one is provided. If no name is provided, the annotation will default to LOCK when used on static methods and to lock for non-static methods. If no field with the specified name exists, one will be generated for you. +

+ The base @Locked annotation uses a java.util.concurrent.locks.Lock for locking. When required, a java.util.concurrent.locks.ReentrantLock is generated.
+ Additionally, there are the @Locked.Read and @Locked.Write annotations. These use a java.util.concurrent.locks.ReadWriteLock. Methods annotated with @Locked.Write will lock on the write lock and methods annotated with @Locked.Read will lock on the read lock. When required, a java.util.concurrent.locks.ReentrantReadWriteLock is generated. +

+ + + <@f.snippets name="experimental/Locked" /> + + <@f.confKeys> +
+ lombok.locked.flagUsage = [warning | error] (default: not set) +
+ Lombok will flag any usage of @Locked as a warning or error if configured. +
+ + + <@f.smallPrint> +

+ Because @Locked.Read and @Locked.Write use a different type of lock than @Locked, these annotations cannot be used on the same lock object.
+ The name of the default field of the @Locked, @Locked.Read, and @Locked.Write annotations is the same, so it is not possible to mix the basic @Locked annotation with the other two using the default name. +

+ + + diff --git a/website/templates/features/experimental/index.html b/website/templates/features/experimental/index.html index a50a4670..12c404bb 100644 --- a/website/templates/features/experimental/index.html +++ b/website/templates/features/experimental/index.html @@ -75,6 +75,10 @@ <@main.feature title="@StandardException" href="StandardException"> Standard.. Exceptional? This is not just an oxymoron, it's convenient! + + <@main.feature title="@Locked" href="Locked"> + TODO + <@f.confKeys> diff --git a/website/usageExamples/experimental/LockedExample_post.jpage b/website/usageExamples/experimental/LockedExample_post.jpage new file mode 100644 index 00000000..86bce0e9 --- /dev/null +++ b/website/usageExamples/experimental/LockedExample_post.jpage @@ -0,0 +1,32 @@ +public class LockedExample { + private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); + private final ReentrantLock baseLock = new ReentrantLock(); + private int value = 0; + + public int getValue() { + this.lock.readLock().lock(); + try { + return value; + } finally { + this.lock.readLock().unlock(); + } + } + + public void setValue(int newValue) { + this.lock.writeLock().lock(); + try { + value = newValue; + } finally { + this.lock.writeLock().unlock(); + } + } + + public void foo() { + this.baseLock.lock(); + try { + System.out.println("bar"); + } finally { + this.baseLock.unlock(); + } + } +} diff --git a/website/usageExamples/experimental/LockedExample_pre.jpage b/website/usageExamples/experimental/LockedExample_pre.jpage new file mode 100644 index 00000000..fdfc7446 --- /dev/null +++ b/website/usageExamples/experimental/LockedExample_pre.jpage @@ -0,0 +1,20 @@ +import lombok.experimental.Locked; + +public class LockedExample { + private int value = 0; + + @Locked.Read + public int getValue() { + return value; + } + + @Locked.Write + public void setValue(int newValue) { + value = newValue; + } + + @Locked("baseLock") + public void foo() { + System.out.println("bar"); + } +}