26 |
|
/** |
27 |
|
* Readlocks succeed after a writing thread unlocks |
28 |
|
*/ |
29 |
< |
public void testReadAfterWriteLock() throws Exception { |
29 |
> |
public void testReadAfterWriteLock() throws Exception { |
30 |
|
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
31 |
|
lock.writeLock().lock(); |
32 |
|
Thread t1 = new Thread(new Runnable() { |
50 |
|
t2.join(MEDIUM_DELAY_MS); |
51 |
|
assertTrue(!t1.isAlive()); |
52 |
|
assertTrue(!t2.isAlive()); |
53 |
< |
|
54 |
< |
} |
53 |
> |
|
54 |
> |
} |
55 |
|
|
56 |
|
/** |
57 |
|
* Read trylock succeeds if write locked by current thread |
58 |
|
*/ |
59 |
< |
public void testReadHoldingWriteLock()throws Exception { |
59 |
> |
public void testReadHoldingWriteLock()throws Exception { |
60 |
|
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
61 |
|
lock.writeLock().lock(); |
62 |
|
assertTrue(lock.readLock().tryLock()); |
63 |
|
lock.readLock().unlock(); |
64 |
|
lock.writeLock().unlock(); |
65 |
< |
} |
65 |
> |
} |
66 |
|
|
67 |
|
/** |
68 |
|
* Read lock succeeds if write locked by current thread even if |
69 |
|
* other threads are waiting |
70 |
|
*/ |
71 |
< |
public void testReadHoldingWriteLock2() throws Exception{ |
71 |
> |
public void testReadHoldingWriteLock2() throws Exception{ |
72 |
|
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
73 |
|
lock.writeLock().lock(); |
74 |
|
Thread t1 = new Thread(new Runnable() { |
83 |
|
lock.readLock().unlock(); |
84 |
|
} |
85 |
|
}); |
86 |
< |
|
86 |
> |
|
87 |
|
t1.start(); |
88 |
|
t2.start(); |
89 |
|
lock.readLock().lock(); |
96 |
|
t2.join(MEDIUM_DELAY_MS); |
97 |
|
assertTrue(!t1.isAlive()); |
98 |
|
assertTrue(!t2.isAlive()); |
99 |
< |
} |
99 |
> |
} |
100 |
|
|
101 |
|
/** |
102 |
|
* Fair Read trylock succeeds if write locked by current thread |
103 |
|
*/ |
104 |
< |
public void testReadHoldingWriteLockFair() throws Exception{ |
104 |
> |
public void testReadHoldingWriteLockFair() throws Exception{ |
105 |
|
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); |
106 |
|
lock.writeLock().lock(); |
107 |
|
assertTrue(lock.readLock().tryLock()); |
108 |
|
lock.readLock().unlock(); |
109 |
|
lock.writeLock().unlock(); |
110 |
< |
} |
110 |
> |
} |
111 |
|
|
112 |
|
/** |
113 |
|
* Fair Read lock succeeds if write locked by current thread even if |
114 |
|
* other threads are waiting |
115 |
|
*/ |
116 |
< |
public void testReadHoldingWriteLockFair2() throws Exception { |
116 |
> |
public void testReadHoldingWriteLockFair2() throws Exception { |
117 |
|
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); |
118 |
|
lock.writeLock().lock(); |
119 |
|
Thread t1 = new Thread(new Runnable() { |
141 |
|
t2.join(MEDIUM_DELAY_MS); |
142 |
|
assertTrue(!t1.isAlive()); |
143 |
|
assertTrue(!t2.isAlive()); |
144 |
– |
|
144 |
|
|
145 |
< |
} |
145 |
> |
|
146 |
> |
} |
147 |
|
} |