mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 20:17:25 +00:00
Add website documentation for Locked annotations
This commit is contained in:
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");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user