Relates :
|
|
Relates :
|
|
Relates :
|
Doug Lea writes: ---------------------------------------------------------------- Contrary to expectations, a recursive writelock attempt may block if there are other waiting threads. This is both a flaw in the spec (which was not clear about this case) and code. Test case: import java.util.concurrent.locks.*; import java.util.concurrent.*; public class T720 { static ReentrantReadWriteLock rl = new ReentrantReadWriteLock(true); static Thread t1 = new Thread() { public void run() { try { if (!rl.readLock().tryLock(2000, TimeUnit.MILLISECONDS)) throw new Error("RRWL ordering error"); Thread.sleep(2000); if (!rl.readLock().tryLock(2000, TimeUnit.MILLISECONDS)) throw new Error("RRWL ordering error"); rl.readLock().unlock(); rl.readLock().unlock(); } catch(InterruptedException ignore) {} } }; static Thread t2 = new Thread() { public void run() { try { Thread.sleep(1000); if (!rl.writeLock().tryLock(2000, TimeUnit.MILLISECONDS)) throw new Error("RRWL ordering error"); Thread.sleep(1000); if (!rl.writeLock().tryLock(2000, TimeUnit.MILLISECONDS)) throw new Error("RRWL ordering error"); } catch(InterruptedException ignore) {} } }; public static void main(String[] args) { t1.start(); t2.start(); } }
|