14 |
|
|
15 |
|
public class ReentrantReadWriteLockTest extends JSR166TestCase { |
16 |
|
public static void main(String[] args) { |
17 |
< |
junit.textui.TestRunner.run (suite()); |
17 |
> |
junit.textui.TestRunner.run (suite()); |
18 |
|
} |
19 |
|
public static Test suite() { |
20 |
< |
return new TestSuite(ReentrantReadWriteLockTest.class); |
20 |
> |
return new TestSuite(ReentrantReadWriteLockTest.class); |
21 |
|
} |
22 |
|
|
23 |
|
/** |
61 |
|
* Constructor sets given fairness, and is in unlocked state |
62 |
|
*/ |
63 |
|
public void testConstructor() { |
64 |
< |
ReentrantReadWriteLock rl = new ReentrantReadWriteLock(); |
64 |
> |
ReentrantReadWriteLock rl = new ReentrantReadWriteLock(); |
65 |
|
assertFalse(rl.isFair()); |
66 |
|
assertFalse(rl.isWriteLocked()); |
67 |
|
assertEquals(0, rl.getReadLockCount()); |
68 |
< |
ReentrantReadWriteLock r2 = new ReentrantReadWriteLock(true); |
68 |
> |
ReentrantReadWriteLock r2 = new ReentrantReadWriteLock(true); |
69 |
|
assertTrue(r2.isFair()); |
70 |
|
assertFalse(r2.isWriteLocked()); |
71 |
|
assertEquals(0, r2.getReadLockCount()); |
72 |
< |
ReentrantReadWriteLock r3 = new ReentrantReadWriteLock(false); |
72 |
> |
ReentrantReadWriteLock r3 = new ReentrantReadWriteLock(false); |
73 |
|
assertFalse(r3.isFair()); |
74 |
|
assertFalse(r3.isWriteLocked()); |
75 |
|
assertEquals(0, r3.getReadLockCount()); |
79 |
|
* write-locking and read-locking an unlocked lock succeed |
80 |
|
*/ |
81 |
|
public void testLock() { |
82 |
< |
ReentrantReadWriteLock rl = new ReentrantReadWriteLock(); |
82 |
> |
ReentrantReadWriteLock rl = new ReentrantReadWriteLock(); |
83 |
|
rl.writeLock().lock(); |
84 |
|
assertTrue(rl.isWriteLocked()); |
85 |
|
assertTrue(rl.isWriteLockedByCurrentThread()); |
105 |
|
* locking an unlocked fair lock succeeds |
106 |
|
*/ |
107 |
|
public void testFairLock() { |
108 |
< |
ReentrantReadWriteLock rl = new ReentrantReadWriteLock(true); |
108 |
> |
ReentrantReadWriteLock rl = new ReentrantReadWriteLock(true); |
109 |
|
rl.writeLock().lock(); |
110 |
|
assertTrue(rl.isWriteLocked()); |
111 |
|
assertTrue(rl.isWriteLockedByCurrentThread()); |
130 |
|
* getWriteHoldCount returns number of recursive holds |
131 |
|
*/ |
132 |
|
public void testGetWriteHoldCount() { |
133 |
< |
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
134 |
< |
for (int i = 1; i <= SIZE; i++) { |
135 |
< |
lock.writeLock().lock(); |
136 |
< |
assertEquals(i,lock.getWriteHoldCount()); |
137 |
< |
} |
138 |
< |
for (int i = SIZE; i > 0; i--) { |
139 |
< |
lock.writeLock().unlock(); |
140 |
< |
assertEquals(i-1,lock.getWriteHoldCount()); |
141 |
< |
} |
133 |
> |
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
134 |
> |
for (int i = 1; i <= SIZE; i++) { |
135 |
> |
lock.writeLock().lock(); |
136 |
> |
assertEquals(i,lock.getWriteHoldCount()); |
137 |
> |
} |
138 |
> |
for (int i = SIZE; i > 0; i--) { |
139 |
> |
lock.writeLock().unlock(); |
140 |
> |
assertEquals(i-1,lock.getWriteHoldCount()); |
141 |
> |
} |
142 |
|
} |
143 |
|
|
144 |
|
/** |
145 |
|
* WriteLock.getHoldCount returns number of recursive holds |
146 |
|
*/ |
147 |
|
public void testGetHoldCount() { |
148 |
< |
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
149 |
< |
for (int i = 1; i <= SIZE; i++) { |
150 |
< |
lock.writeLock().lock(); |
151 |
< |
assertEquals(i,lock.writeLock().getHoldCount()); |
152 |
< |
} |
153 |
< |
for (int i = SIZE; i > 0; i--) { |
154 |
< |
lock.writeLock().unlock(); |
155 |
< |
assertEquals(i-1,lock.writeLock().getHoldCount()); |
156 |
< |
} |
148 |
> |
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
149 |
> |
for (int i = 1; i <= SIZE; i++) { |
150 |
> |
lock.writeLock().lock(); |
151 |
> |
assertEquals(i,lock.writeLock().getHoldCount()); |
152 |
> |
} |
153 |
> |
for (int i = SIZE; i > 0; i--) { |
154 |
> |
lock.writeLock().unlock(); |
155 |
> |
assertEquals(i-1,lock.writeLock().getHoldCount()); |
156 |
> |
} |
157 |
|
} |
158 |
|
|
159 |
|
/** |
160 |
|
* getReadHoldCount returns number of recursive holds |
161 |
|
*/ |
162 |
|
public void testGetReadHoldCount() { |
163 |
< |
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
164 |
< |
for (int i = 1; i <= SIZE; i++) { |
165 |
< |
lock.readLock().lock(); |
166 |
< |
assertEquals(i,lock.getReadHoldCount()); |
167 |
< |
} |
168 |
< |
for (int i = SIZE; i > 0; i--) { |
169 |
< |
lock.readLock().unlock(); |
170 |
< |
assertEquals(i-1,lock.getReadHoldCount()); |
171 |
< |
} |
163 |
> |
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
164 |
> |
for (int i = 1; i <= SIZE; i++) { |
165 |
> |
lock.readLock().lock(); |
166 |
> |
assertEquals(i,lock.getReadHoldCount()); |
167 |
> |
} |
168 |
> |
for (int i = SIZE; i > 0; i--) { |
169 |
> |
lock.readLock().unlock(); |
170 |
> |
assertEquals(i-1,lock.getReadHoldCount()); |
171 |
> |
} |
172 |
|
} |
173 |
|
|
174 |
|
|
176 |
|
* write-unlocking an unlocked lock throws IllegalMonitorStateException |
177 |
|
*/ |
178 |
|
public void testUnlock_IllegalMonitorStateException() { |
179 |
< |
ReentrantReadWriteLock rl = new ReentrantReadWriteLock(); |
180 |
< |
try { |
181 |
< |
rl.writeLock().unlock(); |
182 |
< |
shouldThrow(); |
183 |
< |
} catch (IllegalMonitorStateException success) {} |
179 |
> |
ReentrantReadWriteLock rl = new ReentrantReadWriteLock(); |
180 |
> |
try { |
181 |
> |
rl.writeLock().unlock(); |
182 |
> |
shouldThrow(); |
183 |
> |
} catch (IllegalMonitorStateException success) {} |
184 |
|
} |
185 |
|
|
186 |
|
|
188 |
|
* write-lockInterruptibly is interruptible |
189 |
|
*/ |
190 |
|
public void testWriteLockInterruptibly_Interrupted() throws Exception { |
191 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
192 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
191 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
192 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
193 |
|
public void realRun() throws InterruptedException { |
194 |
|
lock.writeLock().lockInterruptibly(); |
195 |
|
lock.writeLock().unlock(); |
210 |
|
* timed write-tryLock is interruptible |
211 |
|
*/ |
212 |
|
public void testWriteTryLock_Interrupted() throws InterruptedException { |
213 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
214 |
< |
lock.writeLock().lock(); |
215 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
213 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
214 |
> |
lock.writeLock().lock(); |
215 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
216 |
|
public void realRun() throws InterruptedException { |
217 |
|
lock.writeLock().tryLock(1000,TimeUnit.MILLISECONDS); |
218 |
|
}}); |
227 |
|
* read-lockInterruptibly is interruptible |
228 |
|
*/ |
229 |
|
public void testReadLockInterruptibly_Interrupted() throws InterruptedException { |
230 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
231 |
< |
lock.writeLock().lock(); |
232 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
230 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
231 |
> |
lock.writeLock().lock(); |
232 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
233 |
|
public void realRun() throws InterruptedException { |
234 |
|
lock.readLock().lockInterruptibly(); |
235 |
|
}}); |
246 |
|
* timed read-tryLock is interruptible |
247 |
|
*/ |
248 |
|
public void testReadTryLock_Interrupted() throws InterruptedException { |
249 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
250 |
< |
lock.writeLock().lock(); |
251 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
249 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
250 |
> |
lock.writeLock().lock(); |
251 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
252 |
|
public void realRun() throws InterruptedException { |
253 |
|
lock.readLock().tryLock(1000,TimeUnit.MILLISECONDS); |
254 |
|
}}); |
263 |
|
* write-tryLock fails if locked |
264 |
|
*/ |
265 |
|
public void testWriteTryLockWhenLocked() throws InterruptedException { |
266 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
267 |
< |
lock.writeLock().lock(); |
268 |
< |
Thread t = new Thread(new Runnable() { |
266 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
267 |
> |
lock.writeLock().lock(); |
268 |
> |
Thread t = new Thread(new Runnable() { |
269 |
|
public void run() { |
270 |
|
threadAssertFalse(lock.writeLock().tryLock()); |
271 |
< |
} |
272 |
< |
}); |
271 |
> |
} |
272 |
> |
}); |
273 |
|
|
274 |
|
t.start(); |
275 |
|
t.join(); |
280 |
|
* read-tryLock fails if locked |
281 |
|
*/ |
282 |
|
public void testReadTryLockWhenLocked() throws InterruptedException { |
283 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
284 |
< |
lock.writeLock().lock(); |
285 |
< |
Thread t = new Thread(new Runnable() { |
283 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
284 |
> |
lock.writeLock().lock(); |
285 |
> |
Thread t = new Thread(new Runnable() { |
286 |
|
public void run() { |
287 |
|
threadAssertFalse(lock.readLock().tryLock()); |
288 |
< |
} |
289 |
< |
}); |
288 |
> |
} |
289 |
> |
}); |
290 |
|
|
291 |
|
t.start(); |
292 |
|
t.join(); |
297 |
|
* Multiple threads can hold a read lock when not write-locked |
298 |
|
*/ |
299 |
|
public void testMultipleReadLocks() throws InterruptedException { |
300 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
301 |
< |
lock.readLock().lock(); |
302 |
< |
Thread t = new Thread(new Runnable() { |
300 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
301 |
> |
lock.readLock().lock(); |
302 |
> |
Thread t = new Thread(new Runnable() { |
303 |
|
public void run() { |
304 |
|
threadAssertTrue(lock.readLock().tryLock()); |
305 |
|
lock.readLock().unlock(); |
306 |
< |
} |
307 |
< |
}); |
306 |
> |
} |
307 |
> |
}); |
308 |
|
|
309 |
|
t.start(); |
310 |
|
t.join(); |
315 |
|
* A writelock succeeds after reading threads unlock |
316 |
|
*/ |
317 |
|
public void testWriteAfterMultipleReadLocks() throws InterruptedException { |
318 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
319 |
< |
lock.readLock().lock(); |
320 |
< |
Thread t1 = new Thread(new Runnable() { |
318 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
319 |
> |
lock.readLock().lock(); |
320 |
> |
Thread t1 = new Thread(new Runnable() { |
321 |
|
public void run() { |
322 |
|
lock.readLock().lock(); |
323 |
|
lock.readLock().unlock(); |
324 |
< |
} |
325 |
< |
}); |
326 |
< |
Thread t2 = new Thread(new Runnable() { |
324 |
> |
} |
325 |
> |
}); |
326 |
> |
Thread t2 = new Thread(new Runnable() { |
327 |
|
public void run() { |
328 |
|
lock.writeLock().lock(); |
329 |
|
lock.writeLock().unlock(); |
330 |
< |
} |
331 |
< |
}); |
330 |
> |
} |
331 |
> |
}); |
332 |
|
|
333 |
|
t1.start(); |
334 |
|
t2.start(); |
344 |
|
* Readlocks succeed after a writing thread unlocks |
345 |
|
*/ |
346 |
|
public void testReadAfterWriteLock() throws InterruptedException { |
347 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
348 |
< |
lock.writeLock().lock(); |
349 |
< |
Thread t1 = new Thread(new Runnable() { |
347 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
348 |
> |
lock.writeLock().lock(); |
349 |
> |
Thread t1 = new Thread(new Runnable() { |
350 |
|
public void run() { |
351 |
|
lock.readLock().lock(); |
352 |
|
lock.readLock().unlock(); |
353 |
< |
} |
354 |
< |
}); |
355 |
< |
Thread t2 = new Thread(new Runnable() { |
353 |
> |
} |
354 |
> |
}); |
355 |
> |
Thread t2 = new Thread(new Runnable() { |
356 |
|
public void run() { |
357 |
|
lock.readLock().lock(); |
358 |
|
lock.readLock().unlock(); |
359 |
< |
} |
360 |
< |
}); |
359 |
> |
} |
360 |
> |
}); |
361 |
|
|
362 |
|
t1.start(); |
363 |
|
t2.start(); |
373 |
|
* Read trylock succeeds if write locked by current thread |
374 |
|
*/ |
375 |
|
public void testReadHoldingWriteLock() { |
376 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
377 |
< |
lock.writeLock().lock(); |
376 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
377 |
> |
lock.writeLock().lock(); |
378 |
|
assertTrue(lock.readLock().tryLock()); |
379 |
|
lock.readLock().unlock(); |
380 |
|
lock.writeLock().unlock(); |
385 |
|
* other threads are waiting for readlock |
386 |
|
*/ |
387 |
|
public void testReadHoldingWriteLock2() throws InterruptedException { |
388 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
389 |
< |
lock.writeLock().lock(); |
390 |
< |
Thread t1 = new Thread(new Runnable() { |
388 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
389 |
> |
lock.writeLock().lock(); |
390 |
> |
Thread t1 = new Thread(new Runnable() { |
391 |
|
public void run() { |
392 |
|
lock.readLock().lock(); |
393 |
|
lock.readLock().unlock(); |
394 |
< |
} |
395 |
< |
}); |
396 |
< |
Thread t2 = new Thread(new Runnable() { |
394 |
> |
} |
395 |
> |
}); |
396 |
> |
Thread t2 = new Thread(new Runnable() { |
397 |
|
public void run() { |
398 |
|
lock.readLock().lock(); |
399 |
|
lock.readLock().unlock(); |
400 |
< |
} |
401 |
< |
}); |
400 |
> |
} |
401 |
> |
}); |
402 |
|
|
403 |
|
t1.start(); |
404 |
|
t2.start(); |
419 |
|
* other threads are waiting for writelock |
420 |
|
*/ |
421 |
|
public void testReadHoldingWriteLock3() throws InterruptedException { |
422 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
423 |
< |
lock.writeLock().lock(); |
424 |
< |
Thread t1 = new Thread(new Runnable() { |
422 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
423 |
> |
lock.writeLock().lock(); |
424 |
> |
Thread t1 = new Thread(new Runnable() { |
425 |
|
public void run() { |
426 |
|
lock.writeLock().lock(); |
427 |
|
lock.writeLock().unlock(); |
428 |
< |
} |
429 |
< |
}); |
430 |
< |
Thread t2 = new Thread(new Runnable() { |
428 |
> |
} |
429 |
> |
}); |
430 |
> |
Thread t2 = new Thread(new Runnable() { |
431 |
|
public void run() { |
432 |
|
lock.writeLock().lock(); |
433 |
|
lock.writeLock().unlock(); |
434 |
< |
} |
435 |
< |
}); |
434 |
> |
} |
435 |
> |
}); |
436 |
|
|
437 |
|
t1.start(); |
438 |
|
t2.start(); |
454 |
|
* other threads are waiting for writelock |
455 |
|
*/ |
456 |
|
public void testWriteHoldingWriteLock4() throws InterruptedException { |
457 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
458 |
< |
lock.writeLock().lock(); |
459 |
< |
Thread t1 = new Thread(new Runnable() { |
457 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
458 |
> |
lock.writeLock().lock(); |
459 |
> |
Thread t1 = new Thread(new Runnable() { |
460 |
|
public void run() { |
461 |
|
lock.writeLock().lock(); |
462 |
|
lock.writeLock().unlock(); |
463 |
< |
} |
464 |
< |
}); |
465 |
< |
Thread t2 = new Thread(new Runnable() { |
463 |
> |
} |
464 |
> |
}); |
465 |
> |
Thread t2 = new Thread(new Runnable() { |
466 |
|
public void run() { |
467 |
|
lock.writeLock().lock(); |
468 |
|
lock.writeLock().unlock(); |
469 |
< |
} |
470 |
< |
}); |
469 |
> |
} |
470 |
> |
}); |
471 |
|
|
472 |
|
t1.start(); |
473 |
|
t2.start(); |
488 |
|
* Fair Read trylock succeeds if write locked by current thread |
489 |
|
*/ |
490 |
|
public void testReadHoldingWriteLockFair() { |
491 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); |
492 |
< |
lock.writeLock().lock(); |
491 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); |
492 |
> |
lock.writeLock().lock(); |
493 |
|
assertTrue(lock.readLock().tryLock()); |
494 |
|
lock.readLock().unlock(); |
495 |
|
lock.writeLock().unlock(); |
500 |
|
* other threads are waiting for readlock |
501 |
|
*/ |
502 |
|
public void testReadHoldingWriteLockFair2() throws InterruptedException { |
503 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); |
504 |
< |
lock.writeLock().lock(); |
505 |
< |
Thread t1 = new Thread(new Runnable() { |
503 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); |
504 |
> |
lock.writeLock().lock(); |
505 |
> |
Thread t1 = new Thread(new Runnable() { |
506 |
|
public void run() { |
507 |
|
lock.readLock().lock(); |
508 |
|
lock.readLock().unlock(); |
509 |
< |
} |
510 |
< |
}); |
511 |
< |
Thread t2 = new Thread(new Runnable() { |
509 |
> |
} |
510 |
> |
}); |
511 |
> |
Thread t2 = new Thread(new Runnable() { |
512 |
|
public void run() { |
513 |
|
lock.readLock().lock(); |
514 |
|
lock.readLock().unlock(); |
515 |
< |
} |
516 |
< |
}); |
515 |
> |
} |
516 |
> |
}); |
517 |
|
|
518 |
|
t1.start(); |
519 |
|
t2.start(); |
535 |
|
* other threads are waiting for writelock |
536 |
|
*/ |
537 |
|
public void testReadHoldingWriteLockFair3() throws InterruptedException { |
538 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); |
539 |
< |
lock.writeLock().lock(); |
540 |
< |
Thread t1 = new Thread(new Runnable() { |
538 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); |
539 |
> |
lock.writeLock().lock(); |
540 |
> |
Thread t1 = new Thread(new Runnable() { |
541 |
|
public void run() { |
542 |
|
lock.writeLock().lock(); |
543 |
|
lock.writeLock().unlock(); |
544 |
< |
} |
545 |
< |
}); |
546 |
< |
Thread t2 = new Thread(new Runnable() { |
544 |
> |
} |
545 |
> |
}); |
546 |
> |
Thread t2 = new Thread(new Runnable() { |
547 |
|
public void run() { |
548 |
|
lock.writeLock().lock(); |
549 |
|
lock.writeLock().unlock(); |
550 |
< |
} |
551 |
< |
}); |
550 |
> |
} |
551 |
> |
}); |
552 |
|
|
553 |
|
t1.start(); |
554 |
|
t2.start(); |
570 |
|
* other threads are waiting for writelock |
571 |
|
*/ |
572 |
|
public void testWriteHoldingWriteLockFair4() throws InterruptedException { |
573 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); |
574 |
< |
lock.writeLock().lock(); |
575 |
< |
Thread t1 = new Thread(new Runnable() { |
573 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); |
574 |
> |
lock.writeLock().lock(); |
575 |
> |
Thread t1 = new Thread(new Runnable() { |
576 |
|
public void run() { |
577 |
|
lock.writeLock().lock(); |
578 |
|
lock.writeLock().unlock(); |
579 |
< |
} |
580 |
< |
}); |
581 |
< |
Thread t2 = new Thread(new Runnable() { |
579 |
> |
} |
580 |
> |
}); |
581 |
> |
Thread t2 = new Thread(new Runnable() { |
582 |
|
public void run() { |
583 |
|
lock.writeLock().lock(); |
584 |
|
lock.writeLock().unlock(); |
585 |
< |
} |
586 |
< |
}); |
585 |
> |
} |
586 |
> |
}); |
587 |
|
|
588 |
|
t1.start(); |
589 |
|
t2.start(); |
607 |
|
* Read tryLock succeeds if readlocked but not writelocked |
608 |
|
*/ |
609 |
|
public void testTryLockWhenReadLocked() throws InterruptedException { |
610 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
611 |
< |
lock.readLock().lock(); |
612 |
< |
Thread t = new Thread(new Runnable() { |
610 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
611 |
> |
lock.readLock().lock(); |
612 |
> |
Thread t = new Thread(new Runnable() { |
613 |
|
public void run() { |
614 |
|
threadAssertTrue(lock.readLock().tryLock()); |
615 |
|
lock.readLock().unlock(); |
616 |
< |
} |
617 |
< |
}); |
616 |
> |
} |
617 |
> |
}); |
618 |
|
|
619 |
|
t.start(); |
620 |
|
t.join(); |
627 |
|
* write tryLock fails when readlocked |
628 |
|
*/ |
629 |
|
public void testWriteTryLockWhenReadLocked() throws InterruptedException { |
630 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
631 |
< |
lock.readLock().lock(); |
632 |
< |
Thread t = new Thread(new Runnable() { |
630 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
631 |
> |
lock.readLock().lock(); |
632 |
> |
Thread t = new Thread(new Runnable() { |
633 |
|
public void run() { |
634 |
|
threadAssertFalse(lock.writeLock().tryLock()); |
635 |
< |
} |
636 |
< |
}); |
635 |
> |
} |
636 |
> |
}); |
637 |
|
|
638 |
|
t.start(); |
639 |
|
t.join(); |
645 |
|
* Fair Read tryLock succeeds if readlocked but not writelocked |
646 |
|
*/ |
647 |
|
public void testTryLockWhenReadLockedFair() throws InterruptedException { |
648 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); |
649 |
< |
lock.readLock().lock(); |
650 |
< |
Thread t = new Thread(new Runnable() { |
648 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); |
649 |
> |
lock.readLock().lock(); |
650 |
> |
Thread t = new Thread(new Runnable() { |
651 |
|
public void run() { |
652 |
|
threadAssertTrue(lock.readLock().tryLock()); |
653 |
|
lock.readLock().unlock(); |
654 |
< |
} |
655 |
< |
}); |
654 |
> |
} |
655 |
> |
}); |
656 |
|
|
657 |
|
t.start(); |
658 |
|
t.join(); |
665 |
|
* Fair write tryLock fails when readlocked |
666 |
|
*/ |
667 |
|
public void testWriteTryLockWhenReadLockedFair() throws InterruptedException { |
668 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); |
669 |
< |
lock.readLock().lock(); |
670 |
< |
Thread t = new Thread(new Runnable() { |
668 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); |
669 |
> |
lock.readLock().lock(); |
670 |
> |
Thread t = new Thread(new Runnable() { |
671 |
|
public void run() { |
672 |
|
threadAssertFalse(lock.writeLock().tryLock()); |
673 |
< |
} |
674 |
< |
}); |
673 |
> |
} |
674 |
> |
}); |
675 |
|
|
676 |
|
t.start(); |
677 |
|
t.join(); |
684 |
|
* write timed tryLock times out if locked |
685 |
|
*/ |
686 |
|
public void testWriteTryLock_Timeout() throws InterruptedException { |
687 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
688 |
< |
lock.writeLock().lock(); |
689 |
< |
Thread t = new Thread(new CheckedRunnable() { |
687 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
688 |
> |
lock.writeLock().lock(); |
689 |
> |
Thread t = new Thread(new CheckedRunnable() { |
690 |
|
public void realRun() throws InterruptedException { |
691 |
|
threadAssertFalse(lock.writeLock().tryLock(1, TimeUnit.MILLISECONDS)); |
692 |
|
}}); |
693 |
|
|
694 |
|
t.start(); |
695 |
|
t.join(); |
696 |
+ |
assertTrue(lock.writeLock().isHeldByCurrentThread()); |
697 |
|
lock.writeLock().unlock(); |
698 |
|
} |
699 |
|
|
701 |
|
* read timed tryLock times out if write-locked |
702 |
|
*/ |
703 |
|
public void testReadTryLock_Timeout() throws InterruptedException { |
704 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
705 |
< |
lock.writeLock().lock(); |
706 |
< |
Thread t = new Thread(new CheckedRunnable() { |
704 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
705 |
> |
lock.writeLock().lock(); |
706 |
> |
Thread t = new Thread(new CheckedRunnable() { |
707 |
|
public void realRun() throws InterruptedException { |
708 |
|
threadAssertFalse(lock.readLock().tryLock(1, TimeUnit.MILLISECONDS)); |
709 |
|
}}); |
710 |
|
|
711 |
|
t.start(); |
712 |
|
t.join(); |
713 |
+ |
assertTrue(lock.writeLock().isHeldByCurrentThread()); |
714 |
|
lock.writeLock().unlock(); |
715 |
|
} |
716 |
|
|
719 |
|
* write lockInterruptibly succeeds if lock free else is interruptible |
720 |
|
*/ |
721 |
|
public void testWriteLockInterruptibly() throws InterruptedException { |
722 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
722 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
723 |
|
lock.writeLock().lockInterruptibly(); |
724 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
724 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
725 |
|
public void realRun() throws InterruptedException { |
726 |
|
lock.writeLock().lockInterruptibly(); |
727 |
|
}}); |
738 |
|
* read lockInterruptibly succeeds if lock free else is interruptible |
739 |
|
*/ |
740 |
|
public void testReadLockInterruptibly() throws InterruptedException { |
741 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
741 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
742 |
|
lock.writeLock().lockInterruptibly(); |
743 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
743 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
744 |
|
public void realRun() throws InterruptedException { |
745 |
|
lock.readLock().lockInterruptibly(); |
746 |
|
}}); |
756 |
|
* Calling await without holding lock throws IllegalMonitorStateException |
757 |
|
*/ |
758 |
|
public void testAwait_IllegalMonitor() throws InterruptedException { |
759 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
759 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
760 |
|
final Condition c = lock.writeLock().newCondition(); |
761 |
|
try { |
762 |
|
c.await(); |
768 |
|
* Calling signal without holding lock throws IllegalMonitorStateException |
769 |
|
*/ |
770 |
|
public void testSignal_IllegalMonitor() { |
771 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
771 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
772 |
|
final Condition c = lock.writeLock().newCondition(); |
773 |
|
try { |
774 |
|
c.signal(); |
780 |
|
* awaitNanos without a signal times out |
781 |
|
*/ |
782 |
|
public void testAwaitNanos_Timeout() throws InterruptedException { |
783 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
783 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
784 |
|
final Condition c = lock.writeLock().newCondition(); |
785 |
|
|
786 |
|
lock.writeLock().lock(); |
793 |
|
/** |
794 |
|
* timed await without a signal times out |
795 |
|
*/ |
796 |
< |
public void testAwait_Timeout() { |
797 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
796 |
> |
public void testAwait_Timeout() throws InterruptedException { |
797 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
798 |
|
final Condition c = lock.writeLock().newCondition(); |
799 |
|
lock.writeLock().lock(); |
800 |
+ |
assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
801 |
|
lock.writeLock().unlock(); |
802 |
|
} |
803 |
|
|
804 |
|
/** |
805 |
|
* awaitUntil without a signal times out |
806 |
|
*/ |
807 |
< |
public void testAwaitUntil_Timeout() { |
808 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
807 |
> |
public void testAwaitUntil_Timeout() throws InterruptedException { |
808 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
809 |
|
final Condition c = lock.writeLock().newCondition(); |
810 |
|
lock.writeLock().lock(); |
811 |
|
java.util.Date d = new java.util.Date(); |
812 |
+ |
assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + 10))); |
813 |
|
lock.writeLock().unlock(); |
814 |
|
} |
815 |
|
|
817 |
|
* await returns when signalled |
818 |
|
*/ |
819 |
|
public void testAwait() throws InterruptedException { |
820 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
820 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
821 |
|
final Condition c = lock.writeLock().newCondition(); |
822 |
< |
Thread t = new Thread(new CheckedRunnable() { |
822 |
> |
Thread t = new Thread(new CheckedRunnable() { |
823 |
|
public void realRun() throws InterruptedException { |
824 |
|
lock.writeLock().lock(); |
825 |
|
c.await(); |
894 |
|
* await is interruptible |
895 |
|
*/ |
896 |
|
public void testAwait_Interrupt() throws InterruptedException { |
897 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
897 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
898 |
|
final Condition c = lock.writeLock().newCondition(); |
899 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
899 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
900 |
|
public void realRun() throws InterruptedException { |
901 |
|
lock.writeLock().lock(); |
902 |
|
c.await(); |
914 |
|
* awaitNanos is interruptible |
915 |
|
*/ |
916 |
|
public void testAwaitNanos_Interrupt() throws InterruptedException { |
917 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
917 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
918 |
|
final Condition c = lock.writeLock().newCondition(); |
919 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
919 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
920 |
|
public void realRun() throws InterruptedException { |
921 |
|
lock.writeLock().lock(); |
922 |
|
c.awaitNanos(SHORT_DELAY_MS * 2 * 1000000); |
934 |
|
* awaitUntil is interruptible |
935 |
|
*/ |
936 |
|
public void testAwaitUntil_Interrupt() throws InterruptedException { |
937 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
937 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
938 |
|
final Condition c = lock.writeLock().newCondition(); |
939 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
939 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
940 |
|
public void realRun() throws InterruptedException { |
941 |
|
lock.writeLock().lock(); |
942 |
|
java.util.Date d = new java.util.Date(); |
955 |
|
* signalAll wakes up all threads |
956 |
|
*/ |
957 |
|
public void testSignalAll() throws InterruptedException { |
958 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
958 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
959 |
|
final Condition c = lock.writeLock().newCondition(); |
960 |
< |
Thread t1 = new Thread(new CheckedRunnable() { |
960 |
> |
Thread t1 = new Thread(new CheckedRunnable() { |
961 |
|
public void realRun() throws InterruptedException { |
962 |
|
lock.writeLock().lock(); |
963 |
|
c.await(); |
964 |
|
lock.writeLock().unlock(); |
965 |
|
}}); |
966 |
|
|
967 |
< |
Thread t2 = new Thread(new CheckedRunnable() { |
967 |
> |
Thread t2 = new Thread(new CheckedRunnable() { |
968 |
|
public void realRun() throws InterruptedException { |
969 |
|
lock.writeLock().lock(); |
970 |
|
c.await(); |
1007 |
|
* hasQueuedThreads reports whether there are waiting threads |
1008 |
|
*/ |
1009 |
|
public void testhasQueuedThreads() throws InterruptedException { |
1010 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1010 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1011 |
|
Thread t1 = new Thread(new InterruptedLockRunnable(lock)); |
1012 |
|
Thread t2 = new Thread(new InterruptibleLockRunnable(lock)); |
1013 |
|
assertFalse(lock.hasQueuedThreads()); |
1032 |
|
* hasQueuedThread(null) throws NPE |
1033 |
|
*/ |
1034 |
|
public void testHasQueuedThreadNPE() { |
1035 |
< |
final ReentrantReadWriteLock sync = new ReentrantReadWriteLock(); |
1035 |
> |
final ReentrantReadWriteLock sync = new ReentrantReadWriteLock(); |
1036 |
|
try { |
1037 |
|
sync.hasQueuedThread(null); |
1038 |
|
shouldThrow(); |
1043 |
|
* hasQueuedThread reports whether a thread is queued. |
1044 |
|
*/ |
1045 |
|
public void testHasQueuedThread() throws InterruptedException { |
1046 |
< |
final ReentrantReadWriteLock sync = new ReentrantReadWriteLock(); |
1046 |
> |
final ReentrantReadWriteLock sync = new ReentrantReadWriteLock(); |
1047 |
|
Thread t1 = new Thread(new InterruptedLockRunnable(sync)); |
1048 |
|
Thread t2 = new Thread(new InterruptibleLockRunnable(sync)); |
1049 |
|
assertFalse(sync.hasQueuedThread(t1)); |
1074 |
|
* getQueueLength reports number of waiting threads |
1075 |
|
*/ |
1076 |
|
public void testGetQueueLength() throws InterruptedException { |
1077 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1077 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1078 |
|
Thread t1 = new Thread(new InterruptedLockRunnable(lock)); |
1079 |
|
Thread t2 = new Thread(new InterruptibleLockRunnable(lock)); |
1080 |
|
assertEquals(0, lock.getQueueLength()); |
1099 |
|
* getQueuedThreads includes waiting threads |
1100 |
|
*/ |
1101 |
|
public void testGetQueuedThreads() throws InterruptedException { |
1102 |
< |
final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock(); |
1102 |
> |
final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock(); |
1103 |
|
Thread t1 = new Thread(new InterruptedLockRunnable(lock)); |
1104 |
|
Thread t2 = new Thread(new InterruptibleLockRunnable(lock)); |
1105 |
|
assertTrue(lock.getQueuedThreads().isEmpty()); |
1127 |
|
* hasWaiters throws NPE if null |
1128 |
|
*/ |
1129 |
|
public void testHasWaitersNPE() { |
1130 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1130 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1131 |
|
try { |
1132 |
|
lock.hasWaiters(null); |
1133 |
|
shouldThrow(); |
1138 |
|
* getWaitQueueLength throws NPE if null |
1139 |
|
*/ |
1140 |
|
public void testGetWaitQueueLengthNPE() { |
1141 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1141 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1142 |
|
try { |
1143 |
|
lock.getWaitQueueLength(null); |
1144 |
|
shouldThrow(); |
1150 |
|
* getWaitingThreads throws NPE if null |
1151 |
|
*/ |
1152 |
|
public void testGetWaitingThreadsNPE() { |
1153 |
< |
final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock(); |
1153 |
> |
final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock(); |
1154 |
|
try { |
1155 |
|
lock.getWaitingThreads(null); |
1156 |
|
shouldThrow(); |
1161 |
|
* hasWaiters throws IAE if not owned |
1162 |
|
*/ |
1163 |
|
public void testHasWaitersIAE() { |
1164 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1164 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1165 |
|
final Condition c = lock.writeLock().newCondition(); |
1166 |
< |
final ReentrantReadWriteLock lock2 = new ReentrantReadWriteLock(); |
1166 |
> |
final ReentrantReadWriteLock lock2 = new ReentrantReadWriteLock(); |
1167 |
|
try { |
1168 |
|
lock2.hasWaiters(c); |
1169 |
|
shouldThrow(); |
1174 |
|
* hasWaiters throws IMSE if not locked |
1175 |
|
*/ |
1176 |
|
public void testHasWaitersIMSE() { |
1177 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1177 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1178 |
|
final Condition c = lock.writeLock().newCondition(); |
1179 |
|
try { |
1180 |
|
lock.hasWaiters(c); |
1187 |
|
* getWaitQueueLength throws IAE if not owned |
1188 |
|
*/ |
1189 |
|
public void testGetWaitQueueLengthIAE() { |
1190 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1190 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1191 |
|
final Condition c = lock.writeLock().newCondition(); |
1192 |
< |
final ReentrantReadWriteLock lock2 = new ReentrantReadWriteLock(); |
1192 |
> |
final ReentrantReadWriteLock lock2 = new ReentrantReadWriteLock(); |
1193 |
|
try { |
1194 |
|
lock2.getWaitQueueLength(c); |
1195 |
|
shouldThrow(); |
1200 |
|
* getWaitQueueLength throws IMSE if not locked |
1201 |
|
*/ |
1202 |
|
public void testGetWaitQueueLengthIMSE() { |
1203 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1203 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1204 |
|
final Condition c = lock.writeLock().newCondition(); |
1205 |
|
try { |
1206 |
|
lock.getWaitQueueLength(c); |
1213 |
|
* getWaitingThreads throws IAE if not owned |
1214 |
|
*/ |
1215 |
|
public void testGetWaitingThreadsIAE() { |
1216 |
< |
final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock(); |
1216 |
> |
final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock(); |
1217 |
|
final Condition c = lock.writeLock().newCondition(); |
1218 |
< |
final PublicReentrantReadWriteLock lock2 = new PublicReentrantReadWriteLock(); |
1218 |
> |
final PublicReentrantReadWriteLock lock2 = new PublicReentrantReadWriteLock(); |
1219 |
|
try { |
1220 |
|
lock2.getWaitingThreads(c); |
1221 |
|
shouldThrow(); |
1226 |
|
* getWaitingThreads throws IMSE if not locked |
1227 |
|
*/ |
1228 |
|
public void testGetWaitingThreadsIMSE() { |
1229 |
< |
final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock(); |
1229 |
> |
final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock(); |
1230 |
|
final Condition c = lock.writeLock().newCondition(); |
1231 |
|
try { |
1232 |
|
lock.getWaitingThreads(c); |
1239 |
|
* hasWaiters returns true when a thread is waiting, else false |
1240 |
|
*/ |
1241 |
|
public void testHasWaiters() throws InterruptedException { |
1242 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1242 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1243 |
|
final Condition c = lock.writeLock().newCondition(); |
1244 |
< |
Thread t = new Thread(new CheckedRunnable() { |
1244 |
> |
Thread t = new Thread(new CheckedRunnable() { |
1245 |
|
public void realRun() throws InterruptedException { |
1246 |
|
lock.writeLock().lock(); |
1247 |
|
threadAssertFalse(lock.hasWaiters(c)); |
1270 |
|
* getWaitQueueLength returns number of waiting threads |
1271 |
|
*/ |
1272 |
|
public void testGetWaitQueueLength() throws InterruptedException { |
1273 |
< |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1273 |
> |
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
1274 |
|
final Condition c = lock.writeLock().newCondition(); |
1275 |
< |
Thread t = new Thread(new CheckedRunnable() { |
1275 |
> |
Thread t = new Thread(new CheckedRunnable() { |
1276 |
|
public void realRun() throws InterruptedException { |
1277 |
|
lock.writeLock().lock(); |
1278 |
|
threadAssertFalse(lock.hasWaiters(c)); |
1302 |
|
* getWaitingThreads returns only and all waiting threads |
1303 |
|
*/ |
1304 |
|
public void testGetWaitingThreads() throws InterruptedException { |
1305 |
< |
final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock(); |
1305 |
> |
final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock(); |
1306 |
|
final Condition c = lock.writeLock().newCondition(); |
1307 |
< |
Thread t1 = new Thread(new CheckedRunnable() { |
1307 |
> |
Thread t1 = new Thread(new CheckedRunnable() { |
1308 |
|
public void realRun() throws InterruptedException { |
1309 |
|
lock.writeLock().lock(); |
1310 |
|
threadAssertTrue(lock.getWaitingThreads(c).isEmpty()); |
1312 |
|
lock.writeLock().unlock(); |
1313 |
|
}}); |
1314 |
|
|
1315 |
< |
Thread t2 = new Thread(new CheckedRunnable() { |
1315 |
> |
Thread t2 = new Thread(new CheckedRunnable() { |
1316 |
|
public void realRun() throws InterruptedException { |
1317 |
|
lock.writeLock().lock(); |
1318 |
|
threadAssertFalse(lock.getWaitingThreads(c).isEmpty()); |