84 |
|
rl.writeLock().lock(); |
85 |
|
assertTrue(rl.isWriteLocked()); |
86 |
|
assertTrue(rl.isWriteLockedByCurrentThread()); |
87 |
+ |
assertTrue(rl.writeLock().isHeldByCurrentThread()); |
88 |
|
assertEquals(0, rl.getReadLockCount()); |
89 |
|
rl.writeLock().unlock(); |
90 |
|
assertFalse(rl.isWriteLocked()); |
91 |
|
assertFalse(rl.isWriteLockedByCurrentThread()); |
92 |
+ |
assertFalse(rl.writeLock().isHeldByCurrentThread()); |
93 |
|
assertEquals(0, rl.getReadLockCount()); |
94 |
|
rl.readLock().lock(); |
95 |
|
assertFalse(rl.isWriteLocked()); |
110 |
|
rl.writeLock().lock(); |
111 |
|
assertTrue(rl.isWriteLocked()); |
112 |
|
assertTrue(rl.isWriteLockedByCurrentThread()); |
113 |
+ |
assertTrue(rl.writeLock().isHeldByCurrentThread()); |
114 |
|
assertEquals(0, rl.getReadLockCount()); |
115 |
|
rl.writeLock().unlock(); |
116 |
|
assertFalse(rl.isWriteLocked()); |
117 |
|
assertFalse(rl.isWriteLockedByCurrentThread()); |
118 |
+ |
assertFalse(rl.writeLock().isHeldByCurrentThread()); |
119 |
|
assertEquals(0, rl.getReadLockCount()); |
120 |
|
rl.readLock().lock(); |
121 |
|
assertFalse(rl.isWriteLocked()); |
143 |
|
} |
144 |
|
|
145 |
|
/** |
146 |
+ |
* WriteLock.getHoldCount returns number of recursive holds |
147 |
+ |
*/ |
148 |
+ |
public void testGetHoldCount() { |
149 |
+ |
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
150 |
+ |
for(int i = 1; i <= SIZE; i++) { |
151 |
+ |
lock.writeLock().lock(); |
152 |
+ |
assertEquals(i,lock.writeLock().getHoldCount()); |
153 |
+ |
} |
154 |
+ |
for(int i = SIZE; i > 0; i--) { |
155 |
+ |
lock.writeLock().unlock(); |
156 |
+ |
assertEquals(i-1,lock.writeLock().getHoldCount()); |
157 |
+ |
} |
158 |
+ |
} |
159 |
+ |
|
160 |
+ |
/** |
161 |
|
* getReadHoldCount returns number of recursive holds |
162 |
|
*/ |
163 |
|
public void testGetReadHoldCount() { |
203 |
|
try { |
204 |
|
lock.writeLock().lock(); |
205 |
|
t.start(); |
206 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
207 |
|
t.interrupt(); |
208 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
209 |
|
lock.writeLock().unlock(); |
210 |
|
t.join(); |
211 |
|
} catch(Exception e){ |
251 |
|
}); |
252 |
|
try { |
253 |
|
t.start(); |
254 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
255 |
|
t.interrupt(); |
256 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
257 |
|
lock.writeLock().unlock(); |
258 |
|
t.join(); |
259 |
|
} catch(Exception e){ |
838 |
|
}); |
839 |
|
try { |
840 |
|
t.start(); |
841 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
842 |
|
t.interrupt(); |
843 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
844 |
|
t.join(); |
845 |
|
lock.writeLock().unlock(); |
846 |
|
} catch(Exception e){ |
870 |
|
}); |
871 |
|
try { |
872 |
|
t.start(); |
873 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
874 |
|
t.interrupt(); |
875 |
|
t.join(); |
876 |
|
lock.writeLock().unlock(); |