简体   繁体   中英

How is ReentrantLock fair if the same thread keeps acquiring the lock again and again?

I am fairly new to Advanced Java and learning Reentrant locks. I understand that ReentrantLock has a fairness parameter which makes sure that the lock is given to most starving thread (unlike the case in synchronized intrinsic locks.)

However, Reentrant also means that the same thread can reacquire the lock again and again by incrementing the holdCount. If the same thread keeps acquiring lock forever how does it guarantee fairness?

If the thread reenters the lock, it means it hasn't ever unlocked it to leave a fair chance to other threads. Fairness is upon election of the next thread when the lock is not held.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM