ReadWriteSharedLock extends ReentrantReadWriteLock { public boolean isWriteLockedByCurrentThread() { return writers.getReadHoldCount() > 0; }  int getReadHoldCount(); int getReadLockCount(); int getWriteHoldCount(); int getWriteLockCount(); boolean isWriteLockedByCurrentThread(); @Override ReadLock readLock(); @Override String toString(); @Override WriteLock writeLock();  }
@Test public void testIsWriteLockedByCurrentThread() { Runnable a = new Runnable() { @Override public void run() { Assert.assertFalse(lock.isWriteLockedByCurrentThread()); } }; Runnable b = new Runnable() { @Override public void run() { lock.writeLock().lock(); Assert.assertTrue(lock.isWriteLockedByCurrentThread()); } }; for (int i = 0; i < TestData.getScaleCount(); i++) { Thread t = i % 3 == 0 ? new Thread(a) : new Thread(b); t.start(); } }