Alireza Mohamadi Alireza Mohamadi - 3 months ago 31
Java Question

Quasar ReenterantReadWriteLock can't be acquired

I've got a lock:

private ReentrantReadWriteLock requestWaitingLock;

And I'm executing this block inside a

System.out.println("write lock acquired");

And that' because in docs it says:

public void lock()

Acquires the write lock if neither the read nor write lock are held by another strand and returns immediately, setting the write lock hold count to one.

If the current strand already holds the write lock then the hold count is incremented by one and the method returns immediately.

If the lock is held by another strand then the current strand becomes disabled for strand scheduling purposes and lies dormant until the write lock has been acquired, at which time the write lock hold count is set to one.

So I get this output:


This means neither read nor write lock are held by any
at all. So why is my
getting blocked?

EDIT. I'm pretty sure that every fiber which acquires this lock will release it, so it's not possible that other fibers acquire it infinitely.


You seem to call incorrect method to check reader locks:

  • getReadHoldCount - for current thread only
  • getReadLockCount - for all threads in the system