Package org.metricshub.wmi
Class AutoCloseableReadWriteLock
java.lang.Object
java.util.concurrent.locks.ReentrantReadWriteLock
org.metricshub.wmi.AutoCloseableReadWriteLock
- All Implemented Interfaces:
Serializable
,ReadWriteLock
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Auto-closeable version ofReentrantReadWriteLock.ReadLock
static class
Auto-closeable version ofReentrantReadWriteLock.WriteLock
Nested classes/interfaces inherited from class java.util.concurrent.locks.ReentrantReadWriteLock
ReentrantReadWriteLock.ReadLock, ReentrantReadWriteLock.WriteLock
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionread()
Locks the "read lock" of theReentrantReadWriteLock
.write()
Locks the "write lock" of theReentrantReadWriteLock
.Methods inherited from class java.util.concurrent.locks.ReentrantReadWriteLock
getQueueLength, getReadHoldCount, getReadLockCount, getWaitQueueLength, getWriteHoldCount, hasQueuedThread, hasQueuedThreads, hasWaiters, isFair, isWriteLocked, isWriteLockedByCurrentThread, readLock, toString, writeLock
-
Constructor Details
-
AutoCloseableReadWriteLock
public AutoCloseableReadWriteLock()Constructs a new AutoCloseableReadWriteLock.
-
-
Method Details
-
read
Locks the "read lock" of theReentrantReadWriteLock
. Use this to enter a section of the code that doesn't require exclusive access.- Returns:
- An auto-closeable lock, to be used in a try-with-resource block
-
write
Locks the "write lock" of theReentrantReadWriteLock
. Use this to enter a section of the code that requires exclusive access.- Returns:
- An auto-closeable lock, to be used in a try-with-resource block
-