I've read java doc: ReentrantReadWriteLock
And I don't see that writeLock has any priority over readLock
But also I've read topics like this: Are read and write locks in ReentrantReadWriteLock somehow related?
and I see there in both answers following phrases:
if lock is held by readers and thread request write lock no more readers are allowed to acquire read lock until thread which has acquired write lock release it.
Prefers writers over readers. That is, if a writer is waiting on the lock, no new readers from other thread are allowed to access the resource. Existing readers can continue to use the resource until they release the lock. This prevents so-called "writer starvation".
And these phrases sounds meaningfully and looks like I've already read it somewhere else.
But obviously it is a contradiction with java doc.
Was it changed in latest JDK ? is it still valid ?
How to prevent writer starvation ?
ReentrantReadWriteLock describes two modes of operation: fair mode and non-fair mode. The selections that you cited appear to be aiming to describe fair mode. I wouldn't say that either are obviously contradictory. However, I can see where imprecise wording in the first one ("no more readers are allowed") could lead to confusion. I suspect that "more readers" was intended to refer to new readers from other threads, not additional reentrant reads from the same thread, which some might interpret to be the same reader. If interpreted in this way, then they seem consistent with the JavaDoc.