Class AutoCloseableReadWriteLock

java.lang.Object
java.util.concurrent.locks.ReentrantReadWriteLock
org.metricshub.wmi.AutoCloseableReadWriteLock
All Implemented Interfaces:
Serializable, ReadWriteLock

public class AutoCloseableReadWriteLock extends ReentrantReadWriteLock
Auto-closeable version of ReentrantReadWriteLock

Example:


 AutoCloseableReadWriteLock rwLock = new AutoCloseableReadWriteLock();

 try (AutoCloseableReadWriteLock.AutoCloseableReadLock readLock = rwLock.read()) {
        // Do things that do not require exclusive access
 }
 // Read lock (non-exclusive) is unlocked automatically here

 try (AutoCloseableReadWriteLock.AutoCloseableWriteLock writeLock = rwLock.write()) {
        // Do things that require exclusive access
 }
 // Lock is unlocked automatically here
 
See Also: