[docs] Locked example needed its usage examples moved

This commit is contained in:
Reinier Zwitserloot committed 2024-03-20 01:13:12 +01:00
1 parent 0023c598c7
commit d2a18ebf75
2 files changed

No files matched your search

@@ -0,0 +1,32 @@
public class LockedExample {
private final ReadWriteLock lock = new ReentrantReadWriteLock();
private final Lock 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();
}
}
}