use of java.util.concurrent.locks.ReentrantReadWriteLock in project CorfuDB by CorfuDB.
the class MultiReadWriteLock method acquireWriteLock.
/**
* Acquire a write lock. The recommended use of this method is in try-with-resources statement.
* @param address id of the lock to acquire.
* @return A closable that will free the allocations for this lock if necessary
*/
public AutoCloseableLock acquireWriteLock(final Long address) {
registerLockReference(address, true);
ReentrantReadWriteLock lock = constructLockFor(address);
final ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock();
writeLock.lock();
AtomicBoolean closed = new AtomicBoolean(false);
return () -> {
if (!closed.getAndSet(true)) {
try {
writeLock.unlock();
clearEventuallyLockFor(address);
} finally {
deregisterLockReference(address, true);
}
}
};
}
use of java.util.concurrent.locks.ReentrantReadWriteLock in project jgnash by ccavanaugh.
the class SecurityNode method postLoad.
@PostLoad
private void postLoad() {
lock = new ReentrantReadWriteLock(true);
// load the cache list
sortedHistoryNodeCache = new ArrayList<>(historyNodes);
// JPA will be naturally sorted, but XML files will not
Collections.sort(sortedHistoryNodeCache);
}
use of java.util.concurrent.locks.ReentrantReadWriteLock in project jgnash by ccavanaugh.
the class Account method postLoad.
@PostLoad
private void postLoad() {
transactionLock = new ReentrantReadWriteLock(true);
childLock = new ReentrantReadWriteLock(true);
securitiesLock = new ReentrantReadWriteLock(true);
attributesLock = new ReentrantReadWriteLock(true);
cachedSortedChildren = new ArrayList<>(children);
// JPA will be naturally sorted, but XML files will not
Collections.sort(cachedSortedChildren);
}
use of java.util.concurrent.locks.ReentrantReadWriteLock in project hbase by apache.
the class TestBucketCache method testMemoryLeak.
@Test
public void testMemoryLeak() throws Exception {
final BlockCacheKey cacheKey = new BlockCacheKey("dummy", 1L);
cacheAndWaitUntilFlushedToBucket(cache, cacheKey, new CacheTestUtils.ByteArrayCacheable(new byte[10]));
long lockId = cache.backingMap.get(cacheKey).offset();
ReentrantReadWriteLock lock = cache.offsetLock.getLock(lockId);
lock.writeLock().lock();
Thread evictThread = new Thread("evict-block") {
@Override
public void run() {
cache.evictBlock(cacheKey);
}
};
evictThread.start();
cache.offsetLock.waitForWaiters(lockId, 1);
cache.blockEvicted(cacheKey, cache.backingMap.remove(cacheKey), true);
cacheAndWaitUntilFlushedToBucket(cache, cacheKey, new CacheTestUtils.ByteArrayCacheable(new byte[10]));
lock.writeLock().unlock();
evictThread.join();
assertEquals(1L, cache.getBlockCount());
assertTrue(cache.getCurrentSize() > 0L);
assertTrue("We should have a block!", cache.iterator().hasNext());
}
use of java.util.concurrent.locks.ReentrantReadWriteLock in project hbase by apache.
the class IdReadWriteLock method getLock.
/**
* Get the ReentrantReadWriteLock corresponding to the given id
* @param id an arbitrary number to identify the lock
*/
public ReentrantReadWriteLock getLock(long id) {
lockPool.purge();
ReentrantReadWriteLock readWriteLock = lockPool.get(id);
return readWriteLock;
}
Aggregations