@Test public void ensure_that_two_different_lock_are_returned_when_threshold_is_reached() { ReentrantReadWriteLockGroup locks = new ReentrantReadWriteLockGroup(true, 1); ReentrantReadWriteLock firstLockForOneValue = locks.getLock("1"); Runnable runnable = new Runnable() { @Override public void run() { firstLockForOneValue.writeLock().lock(); } }; Thread t = new Thread(runnable); t.start(); try { t.join(); } catch (InterruptedException e) { e.printStackTrace(); } ReentrantReadWriteLock firstLockForTwoValue = locks.getLock("2"); ReentrantReadWriteLock secondLockForOneValue = locks.getLock("1"); assertEquals(firstLockForOneValue, secondLockForOneValue); }
public ReentrantReadWriteLock getLock(String id) { ReentrantReadWriteLock lock = locks.get(id); if (lock == null) { locks.putIfAbsent(id, new ReentrantReadWriteLock(fairness)); } lock = locks.get(id); if (CLEANUP_THRESHOLD <= ++counter) { cleanUp(lock); counter = 0; } return lock; }
ReentrantReadWriteLockGroup { public ReentrantReadWriteLock getLock(String id) { ReentrantReadWriteLock lock = locks.get(id); if (lock == null) { locks.putIfAbsent(id, new ReentrantReadWriteLock(fairness)); } lock = locks.get(id); if (CLEANUP_THRESHOLD <= ++counter) { cleanUp(lock); counter = 0; } return lock; } }
ReentrantReadWriteLockGroup { public ReentrantReadWriteLock getLock(String id) { ReentrantReadWriteLock lock = locks.get(id); if (lock == null) { locks.putIfAbsent(id, new ReentrantReadWriteLock(fairness)); } lock = locks.get(id); if (CLEANUP_THRESHOLD <= ++counter) { cleanUp(lock); counter = 0; } return lock; } ReentrantReadWriteLockGroup();  ReentrantReadWriteLockGroup(int counter);  ReentrantReadWriteLockGroup(boolean fairness);  ReentrantReadWriteLockGroup(boolean fairness, int counter); }
ReentrantReadWriteLockGroup { public ReentrantReadWriteLock getLock(String id) { ReentrantReadWriteLock lock = locks.get(id); if (lock == null) { locks.putIfAbsent(id, new ReentrantReadWriteLock(fairness)); } lock = locks.get(id); if (CLEANUP_THRESHOLD <= ++counter) { cleanUp(lock); counter = 0; } return lock; } ReentrantReadWriteLockGroup();  ReentrantReadWriteLockGroup(int counter);  ReentrantReadWriteLockGroup(boolean fairness);  ReentrantReadWriteLockGroup(boolean fairness, int counter); ReentrantReadWriteLock getLock(String id); }
ReentrantReadWriteLockGroup { public ReentrantReadWriteLock getLock(String id) { ReentrantReadWriteLock lock = locks.get(id); if (lock == null) { locks.putIfAbsent(id, new ReentrantReadWriteLock(fairness)); } lock = locks.get(id); if (CLEANUP_THRESHOLD <= ++counter) { cleanUp(lock); counter = 0; } return lock; } ReentrantReadWriteLockGroup();  ReentrantReadWriteLockGroup(int counter);  ReentrantReadWriteLockGroup(boolean fairness);  ReentrantReadWriteLockGroup(boolean fairness, int counter); ReentrantReadWriteLock getLock(String id);  }