public class AutoCloseableReadWriteLock extends Object implements ReadWriteLock
ReentrantReadWriteLock that, when
combined with try-with-resources pattern, automatically unlocks the lock once the try
section is completed.
Usage example:
AutoCloseableReadWriteLock lock = new AutoCloseableReadWriteLock();
try (AutoCloseableLock readLock = lock.readLock()) {
// no other thread can acquire write lock while this section is running
}
// the readLock is automatically unlocked
| Constructor and Description |
|---|
AutoCloseableReadWriteLock() |
| Modifier and Type | Method and Description |
|---|---|
AutoCloseableLock |
readLock() |
AutoCloseableLock |
writeLock() |
public AutoCloseableLock readLock()
readLock in interface ReadWriteLockpublic AutoCloseableLock writeLock()
writeLock in interface ReadWriteLock