Add website documentation for Locked annotations

This commit is contained in:
Pim van der Loos committed 2023-04-18 18:07:53 +02:00
1 parent cb25fce7aa
commit 0129a0d18b
4 files changed
+101

No files matched your search

@@ -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();
}
}
}
@@ -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");
}
}