ade lock: rwl.readLock().release(); // must release first to obtain writelock rwl.writeLock().acquire(); if (!cacheValid) { // recheck data = ... cacheValid = true; } // downgrade lock rwl.readLock().acquire(); // reacquire read without giving up lock rwl.writeLock().release(); // release write, still hold read } use(data); rwl.readLock().release(); } }
[ Introduction to this package. ]
@see ReentrantLock