I am implementing a database which can read and write data. For concurrency issue, I need to implement lock. Normally, ReentrantReadWriteLock will let write execute before read. How Can I go reversely? Is there a way that I can read before write thread executes?
Asked
Active
Viewed 240 times
1 Answers
4
Re-read the javadoc of ReentrantReadWriteLock. It doesn't impose any order between reads and writes. All it does is allowing concurrent reads, but disallowing concurrent writes and writes concurrent with reads.
This class has the following properties:
Acquisition order
- This class does not impose a reader or writer preference ordering for lock access. However, it does support an optional fairness policy.

JB Nizet
- 678,734
- 91
- 1,224
- 1,255
-
the link you gave to me is ReentrantLock, it is slightly different from ReentrantReadWriteLock – Kevin Qu May 15 '12 at 07:43
-
Sorry, I took the wrong URL. Fixed now. The javadoc citation is from the javadoc of ReentrantReadWriteLock though, and my answer still stands. Read the javadoc. – JB Nizet May 15 '12 at 07:47