I could use one semaphore to lock all
reads and writes but I don't think
that performs very well.
With respect to performance, NEVER think. ALWAYS measure.
That said, java.util.concurrent.locks.ReentrantReadWriteLock
is what you are looking for.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…