29 |
|
public void run() { |
30 |
|
try { |
31 |
|
lock.writeLock().lockInterruptibly(); |
32 |
< |
} catch(InterruptedException success){} |
32 |
> |
} catch (InterruptedException success){} |
33 |
|
} |
34 |
|
} |
35 |
|
|
45 |
|
try { |
46 |
|
lock.writeLock().lockInterruptibly(); |
47 |
|
threadShouldThrow(); |
48 |
< |
} catch(InterruptedException success){} |
48 |
> |
} catch (InterruptedException success){} |
49 |
|
} |
50 |
|
} |
51 |
|
|
132 |
|
*/ |
133 |
|
public void testGetWriteHoldCount() { |
134 |
|
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
135 |
< |
for(int i = 1; i <= SIZE; i++) { |
135 |
> |
for (int i = 1; i <= SIZE; i++) { |
136 |
|
lock.writeLock().lock(); |
137 |
|
assertEquals(i,lock.getWriteHoldCount()); |
138 |
|
} |
139 |
< |
for(int i = SIZE; i > 0; i--) { |
139 |
> |
for (int i = SIZE; i > 0; i--) { |
140 |
|
lock.writeLock().unlock(); |
141 |
|
assertEquals(i-1,lock.getWriteHoldCount()); |
142 |
|
} |
147 |
|
*/ |
148 |
|
public void testGetHoldCount() { |
149 |
|
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
150 |
< |
for(int i = 1; i <= SIZE; i++) { |
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--) { |
154 |
> |
for (int i = SIZE; i > 0; i--) { |
155 |
|
lock.writeLock().unlock(); |
156 |
|
assertEquals(i-1,lock.writeLock().getHoldCount()); |
157 |
|
} |
162 |
|
*/ |
163 |
|
public void testGetReadHoldCount() { |
164 |
|
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
165 |
< |
for(int i = 1; i <= SIZE; i++) { |
165 |
> |
for (int i = 1; i <= SIZE; i++) { |
166 |
|
lock.readLock().lock(); |
167 |
|
assertEquals(i,lock.getReadHoldCount()); |
168 |
|
} |
169 |
< |
for(int i = SIZE; i > 0; i--) { |
169 |
> |
for (int i = SIZE; i > 0; i--) { |
170 |
|
lock.readLock().unlock(); |
171 |
|
assertEquals(i-1,lock.getReadHoldCount()); |
172 |
|
} |
181 |
|
try { |
182 |
|
rl.writeLock().unlock(); |
183 |
|
shouldThrow(); |
184 |
< |
} catch(IllegalMonitorStateException success){} |
184 |
> |
} catch (IllegalMonitorStateException success){} |
185 |
|
} |
186 |
|
|
187 |
|
|
197 |
|
lock.writeLock().unlock(); |
198 |
|
lock.writeLock().lockInterruptibly(); |
199 |
|
lock.writeLock().unlock(); |
200 |
< |
} catch(InterruptedException success){} |
200 |
> |
} catch (InterruptedException success){} |
201 |
|
} |
202 |
|
}); |
203 |
|
try { |
208 |
|
Thread.sleep(SHORT_DELAY_MS); |
209 |
|
lock.writeLock().unlock(); |
210 |
|
t.join(); |
211 |
< |
} catch(Exception e){ |
211 |
> |
} catch (Exception e){ |
212 |
|
unexpectedException(); |
213 |
|
} |
214 |
|
} |
223 |
|
public void run() { |
224 |
|
try { |
225 |
|
lock.writeLock().tryLock(1000,TimeUnit.MILLISECONDS); |
226 |
< |
} catch(InterruptedException success){} |
226 |
> |
} catch (InterruptedException success){} |
227 |
|
} |
228 |
|
}); |
229 |
|
try { |
231 |
|
t.interrupt(); |
232 |
|
lock.writeLock().unlock(); |
233 |
|
t.join(); |
234 |
< |
} catch(Exception e){ |
234 |
> |
} catch (Exception e){ |
235 |
|
unexpectedException(); |
236 |
|
} |
237 |
|
} |
246 |
|
public void run() { |
247 |
|
try { |
248 |
|
lock.readLock().lockInterruptibly(); |
249 |
< |
} catch(InterruptedException success){} |
249 |
> |
} catch (InterruptedException success){} |
250 |
|
} |
251 |
|
}); |
252 |
|
try { |
256 |
|
Thread.sleep(SHORT_DELAY_MS); |
257 |
|
lock.writeLock().unlock(); |
258 |
|
t.join(); |
259 |
< |
} catch(Exception e){ |
259 |
> |
} catch (Exception e){ |
260 |
|
unexpectedException(); |
261 |
|
} |
262 |
|
} |
272 |
|
try { |
273 |
|
lock.readLock().tryLock(1000,TimeUnit.MILLISECONDS); |
274 |
|
threadShouldThrow(); |
275 |
< |
} catch(InterruptedException success){} |
275 |
> |
} catch (InterruptedException success){} |
276 |
|
} |
277 |
|
}); |
278 |
|
try { |
279 |
|
t.start(); |
280 |
|
t.interrupt(); |
281 |
|
t.join(); |
282 |
< |
} catch(Exception e){ |
282 |
> |
} catch (Exception e){ |
283 |
|
unexpectedException(); |
284 |
|
} |
285 |
|
} |
300 |
|
t.start(); |
301 |
|
t.join(); |
302 |
|
lock.writeLock().unlock(); |
303 |
< |
} catch(Exception e){ |
303 |
> |
} catch (Exception e){ |
304 |
|
unexpectedException(); |
305 |
|
} |
306 |
|
} |
320 |
|
t.start(); |
321 |
|
t.join(); |
322 |
|
lock.writeLock().unlock(); |
323 |
< |
} catch(Exception e){ |
323 |
> |
} catch (Exception e){ |
324 |
|
unexpectedException(); |
325 |
|
} |
326 |
|
} |
341 |
|
t.start(); |
342 |
|
t.join(); |
343 |
|
lock.readLock().unlock(); |
344 |
< |
} catch(Exception e){ |
344 |
> |
} catch (Exception e){ |
345 |
|
unexpectedException(); |
346 |
|
} |
347 |
|
} |
375 |
|
assertTrue(!t1.isAlive()); |
376 |
|
assertTrue(!t2.isAlive()); |
377 |
|
|
378 |
< |
} catch(Exception e){ |
378 |
> |
} catch (Exception e){ |
379 |
|
unexpectedException(); |
380 |
|
} |
381 |
|
} |
409 |
|
assertTrue(!t1.isAlive()); |
410 |
|
assertTrue(!t2.isAlive()); |
411 |
|
|
412 |
< |
} catch(Exception e){ |
412 |
> |
} catch (Exception e){ |
413 |
|
unexpectedException(); |
414 |
|
} |
415 |
|
} |
459 |
|
assertTrue(!t1.isAlive()); |
460 |
|
assertTrue(!t2.isAlive()); |
461 |
|
|
462 |
< |
} catch(Exception e){ |
462 |
> |
} catch (Exception e){ |
463 |
|
unexpectedException(); |
464 |
|
} |
465 |
|
} |
498 |
|
assertTrue(!t1.isAlive()); |
499 |
|
assertTrue(!t2.isAlive()); |
500 |
|
|
501 |
< |
} catch(Exception e){ |
501 |
> |
} catch (Exception e){ |
502 |
|
unexpectedException(); |
503 |
|
} |
504 |
|
} |
538 |
|
assertTrue(!t1.isAlive()); |
539 |
|
assertTrue(!t2.isAlive()); |
540 |
|
|
541 |
< |
} catch(Exception e){ |
541 |
> |
} catch (Exception e){ |
542 |
|
unexpectedException(); |
543 |
|
} |
544 |
|
} |
589 |
|
assertTrue(!t1.isAlive()); |
590 |
|
assertTrue(!t2.isAlive()); |
591 |
|
|
592 |
< |
} catch(Exception e){ |
592 |
> |
} catch (Exception e){ |
593 |
|
unexpectedException(); |
594 |
|
} |
595 |
|
} |
629 |
|
assertTrue(!t1.isAlive()); |
630 |
|
assertTrue(!t2.isAlive()); |
631 |
|
|
632 |
< |
} catch(Exception e){ |
632 |
> |
} catch (Exception e){ |
633 |
|
unexpectedException(); |
634 |
|
} |
635 |
|
} |
672 |
|
assertTrue(!t1.isAlive()); |
673 |
|
assertTrue(!t2.isAlive()); |
674 |
|
|
675 |
< |
} catch(Exception e){ |
675 |
> |
} catch (Exception e){ |
676 |
|
unexpectedException(); |
677 |
|
} |
678 |
|
} |
694 |
|
t.start(); |
695 |
|
t.join(); |
696 |
|
lock.readLock().unlock(); |
697 |
< |
} catch(Exception e){ |
697 |
> |
} catch (Exception e){ |
698 |
|
unexpectedException(); |
699 |
|
} |
700 |
|
} |
716 |
|
t.start(); |
717 |
|
t.join(); |
718 |
|
lock.readLock().unlock(); |
719 |
< |
} catch(Exception e){ |
719 |
> |
} catch (Exception e){ |
720 |
|
unexpectedException(); |
721 |
|
} |
722 |
|
} |
738 |
|
t.start(); |
739 |
|
t.join(); |
740 |
|
lock.readLock().unlock(); |
741 |
< |
} catch(Exception e){ |
741 |
> |
} catch (Exception e){ |
742 |
|
unexpectedException(); |
743 |
|
} |
744 |
|
} |
760 |
|
t.start(); |
761 |
|
t.join(); |
762 |
|
lock.readLock().unlock(); |
763 |
< |
} catch(Exception e){ |
763 |
> |
} catch (Exception e){ |
764 |
|
unexpectedException(); |
765 |
|
} |
766 |
|
} |
786 |
|
t.start(); |
787 |
|
t.join(); |
788 |
|
lock.writeLock().unlock(); |
789 |
< |
} catch(Exception e){ |
789 |
> |
} catch (Exception e){ |
790 |
|
unexpectedException(); |
791 |
|
} |
792 |
|
} |
810 |
|
t.start(); |
811 |
|
t.join(); |
812 |
|
lock.writeLock().unlock(); |
813 |
< |
} catch(Exception e){ |
813 |
> |
} catch (Exception e){ |
814 |
|
unexpectedException(); |
815 |
|
} |
816 |
|
} |
823 |
|
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
824 |
|
try { |
825 |
|
lock.writeLock().lockInterruptibly(); |
826 |
< |
} catch(Exception e) { |
826 |
> |
} catch (Exception e) { |
827 |
|
unexpectedException(); |
828 |
|
} |
829 |
|
Thread t = new Thread(new Runnable() { |
832 |
|
lock.writeLock().lockInterruptibly(); |
833 |
|
threadShouldThrow(); |
834 |
|
} |
835 |
< |
catch(InterruptedException success) { |
835 |
> |
catch (InterruptedException success) { |
836 |
|
} |
837 |
|
} |
838 |
|
}); |
843 |
|
Thread.sleep(SHORT_DELAY_MS); |
844 |
|
t.join(); |
845 |
|
lock.writeLock().unlock(); |
846 |
< |
} catch(Exception e){ |
846 |
> |
} catch (Exception e){ |
847 |
|
unexpectedException(); |
848 |
|
} |
849 |
|
} |
855 |
|
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
856 |
|
try { |
857 |
|
lock.writeLock().lockInterruptibly(); |
858 |
< |
} catch(Exception e) { |
858 |
> |
} catch (Exception e) { |
859 |
|
unexpectedException(); |
860 |
|
} |
861 |
|
Thread t = new Thread(new Runnable() { |
864 |
|
lock.readLock().lockInterruptibly(); |
865 |
|
threadShouldThrow(); |
866 |
|
} |
867 |
< |
catch(InterruptedException success) { |
867 |
> |
catch (InterruptedException success) { |
868 |
|
} |
869 |
|
} |
870 |
|
}); |
874 |
|
t.interrupt(); |
875 |
|
t.join(); |
876 |
|
lock.writeLock().unlock(); |
877 |
< |
} catch(Exception e){ |
877 |
> |
} catch (Exception e){ |
878 |
|
unexpectedException(); |
879 |
|
} |
880 |
|
} |
975 |
|
c.await(); |
976 |
|
lock.writeLock().unlock(); |
977 |
|
} |
978 |
< |
catch(InterruptedException e) { |
978 |
> |
catch (InterruptedException e) { |
979 |
|
threadUnexpectedException(); |
980 |
|
} |
981 |
|
} |
1068 |
|
lock.writeLock().unlock(); |
1069 |
|
threadShouldThrow(); |
1070 |
|
} |
1071 |
< |
catch(InterruptedException success) { |
1071 |
> |
catch (InterruptedException success) { |
1072 |
|
} |
1073 |
|
} |
1074 |
|
}); |
1099 |
|
lock.writeLock().unlock(); |
1100 |
|
threadShouldThrow(); |
1101 |
|
} |
1102 |
< |
catch(InterruptedException success) { |
1102 |
> |
catch (InterruptedException success) { |
1103 |
|
} |
1104 |
|
} |
1105 |
|
}); |
1131 |
|
lock.writeLock().unlock(); |
1132 |
|
threadShouldThrow(); |
1133 |
|
} |
1134 |
< |
catch(InterruptedException success) { |
1134 |
> |
catch (InterruptedException success) { |
1135 |
|
} |
1136 |
|
} |
1137 |
|
}); |
1161 |
|
c.await(); |
1162 |
|
lock.writeLock().unlock(); |
1163 |
|
} |
1164 |
< |
catch(InterruptedException e) { |
1164 |
> |
catch (InterruptedException e) { |
1165 |
|
threadUnexpectedException(); |
1166 |
|
} |
1167 |
|
} |
1174 |
|
c.await(); |
1175 |
|
lock.writeLock().unlock(); |
1176 |
|
} |
1177 |
< |
catch(InterruptedException e) { |
1177 |
> |
catch (InterruptedException e) { |
1178 |
|
threadUnexpectedException(); |
1179 |
|
} |
1180 |
|
} |
1216 |
|
ReentrantReadWriteLock r = (ReentrantReadWriteLock) in.readObject(); |
1217 |
|
r.readLock().lock(); |
1218 |
|
r.readLock().unlock(); |
1219 |
< |
} catch(Exception e){ |
1219 |
> |
} catch (Exception e){ |
1220 |
|
e.printStackTrace(); |
1221 |
|
unexpectedException(); |
1222 |
|
} |
1246 |
|
assertFalse(lock.hasQueuedThreads()); |
1247 |
|
t1.join(); |
1248 |
|
t2.join(); |
1249 |
< |
} catch(Exception e){ |
1249 |
> |
} catch (Exception e){ |
1250 |
|
unexpectedException(); |
1251 |
|
} |
1252 |
|
} |
1292 |
|
assertFalse(sync.hasQueuedThread(t2)); |
1293 |
|
t1.join(); |
1294 |
|
t2.join(); |
1295 |
< |
} catch(Exception e){ |
1295 |
> |
} catch (Exception e){ |
1296 |
|
unexpectedException(); |
1297 |
|
} |
1298 |
|
} |
1322 |
|
assertEquals(0, lock.getQueueLength()); |
1323 |
|
t1.join(); |
1324 |
|
t2.join(); |
1325 |
< |
} catch(Exception e){ |
1325 |
> |
} catch (Exception e){ |
1326 |
|
unexpectedException(); |
1327 |
|
} |
1328 |
|
} |
1354 |
|
assertTrue(lock.getQueuedThreads().isEmpty()); |
1355 |
|
t1.join(); |
1356 |
|
t2.join(); |
1357 |
< |
} catch(Exception e){ |
1357 |
> |
} catch (Exception e){ |
1358 |
|
unexpectedException(); |
1359 |
|
} |
1360 |
|
} |
1513 |
|
c.await(); |
1514 |
|
lock.writeLock().unlock(); |
1515 |
|
} |
1516 |
< |
catch(InterruptedException e) { |
1516 |
> |
catch (InterruptedException e) { |
1517 |
|
threadUnexpectedException(); |
1518 |
|
} |
1519 |
|
} |
1555 |
|
c.await(); |
1556 |
|
lock.writeLock().unlock(); |
1557 |
|
} |
1558 |
< |
catch(InterruptedException e) { |
1558 |
> |
catch (InterruptedException e) { |
1559 |
|
threadUnexpectedException(); |
1560 |
|
} |
1561 |
|
} |
1597 |
|
c.await(); |
1598 |
|
lock.writeLock().unlock(); |
1599 |
|
} |
1600 |
< |
catch(InterruptedException e) { |
1600 |
> |
catch (InterruptedException e) { |
1601 |
|
threadUnexpectedException(); |
1602 |
|
} |
1603 |
|
} |
1611 |
|
c.await(); |
1612 |
|
lock.writeLock().unlock(); |
1613 |
|
} |
1614 |
< |
catch(InterruptedException e) { |
1614 |
> |
catch (InterruptedException e) { |
1615 |
|
threadUnexpectedException(); |
1616 |
|
} |
1617 |
|
} |