I create a java.util.concurrent.locks.ReentrantReadWriteLock using
new java.util.concurrent.locks.ReentrantReadWriteLock().readLock()
and then I pass to a method as Lock interface
method(Lock lock)
Now I want to find how many readlocks are possessed by the current thread. How can i achieve this?
I can’t cast it again into ReentrantReadWriteLock . What should I do? How I can get this count?
To get the read lock count on the ReentrantReadWriteLock, you need to call lock.getReadHoldCount()
To get this from the ReadLock alone, you need to get the “sync” field and call “getReadHoldCount()” via reflection.
An example of using reflection to access a lock is as follows.
What you can do is create a wrapper.