2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
|
* http://creativecommons.org/licenses/publicdomain |
5 |
< |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
< |
* Pat Fisher, Mike Judd. |
5 |
> |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
> |
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
10 |
|
import java.util.*; |
11 |
|
import java.util.concurrent.*; |
12 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
13 |
|
import java.io.*; |
14 |
|
import java.security.*; |
15 |
|
|
18 |
|
* utility methods and classes, as well as a simple framework for |
19 |
|
* helping to make sure that assertions failing in generated threads |
20 |
|
* cause the associated test that generated them to itself fail (which |
21 |
< |
* JUnit doe not otherwise arrange). The rules for creating such |
21 |
> |
* JUnit does not otherwise arrange). The rules for creating such |
22 |
|
* tests are: |
23 |
|
* |
24 |
|
* <ol> |
25 |
|
* |
26 |
|
* <li> All assertions in code running in generated threads must use |
27 |
< |
* the forms {@link threadFail} , {@link threadAssertTrue} {@link |
28 |
< |
* threadAssertEquals}, or {@link threadAssertNull}, (not |
27 |
> |
* the forms {@link #threadFail}, {@link #threadAssertTrue}, {@link |
28 |
> |
* #threadAssertEquals}, or {@link #threadAssertNull}, (not |
29 |
|
* <tt>fail</tt>, <tt>assertTrue</tt>, etc.) It is OK (but not |
30 |
|
* particularly recommended) for other code to use these forms too. |
31 |
|
* Only the most typically used JUnit assertion methods are defined |
32 |
|
* this way, but enough to live with.</li> |
33 |
|
* |
34 |
< |
* <li> If you override {@link setUp} or {@link tearDown}, make sure |
34 |
> |
* <li> If you override {@link #setUp} or {@link #tearDown}, make sure |
35 |
|
* to invoke <tt>super.setUp</tt> and <tt>super.tearDown</tt> within |
36 |
|
* them. These methods are used to clear and check for thread |
37 |
|
* assertion failures.</li> |
45 |
|
* is always discriminable as larger than SHORT and smaller than |
46 |
|
* MEDIUM. And so on. These constants are set to conservative values, |
47 |
|
* but even so, if there is ever any doubt, they can all be increased |
48 |
< |
* in one spot to rerun tests on slower platforms</li> |
48 |
> |
* in one spot to rerun tests on slower platforms.</li> |
49 |
|
* |
50 |
|
* <li> All threads generated must be joined inside each test case |
51 |
|
* method (or <tt>fail</tt> to do so) before returning from the |
64 |
|
* "normal" behaviors differ significantly. And sometimes testcases |
65 |
|
* cover multiple methods when they cannot be tested in |
66 |
|
* isolation.</li> |
67 |
< |
* |
67 |
> |
* |
68 |
|
* <li> The documentation style for testcases is to provide as javadoc |
69 |
|
* a simple sentence or two describing the property that the testcase |
70 |
|
* method purports to test. The javadocs do not say anything about how |
89 |
|
public class JSR166TestCase extends TestCase { |
90 |
|
/** |
91 |
|
* Runs all JSR166 unit tests using junit.textui.TestRunner |
92 |
< |
*/ |
92 |
> |
*/ |
93 |
|
public static void main (String[] args) { |
94 |
< |
junit.textui.TestRunner.run (suite()); |
94 |
> |
int iters = 1; |
95 |
> |
if (args.length > 0) |
96 |
> |
iters = Integer.parseInt(args[0]); |
97 |
> |
Test s = suite(); |
98 |
> |
for (int i = 0; i < iters; ++i) { |
99 |
> |
junit.textui.TestRunner.run (s); |
100 |
> |
System.gc(); |
101 |
> |
System.runFinalization(); |
102 |
> |
} |
103 |
> |
System.exit(0); |
104 |
|
} |
105 |
|
|
106 |
|
/** |
107 |
|
* Collects all JSR166 unit tests as one suite |
108 |
< |
*/ |
108 |
> |
*/ |
109 |
|
public static Test suite ( ) { |
110 |
|
TestSuite suite = new TestSuite("JSR166 Unit Tests"); |
111 |
< |
|
111 |
> |
|
112 |
> |
suite.addTest(new TestSuite(ForkJoinPoolTest.class)); |
113 |
> |
suite.addTest(new TestSuite(ForkJoinTaskTest.class)); |
114 |
> |
suite.addTest(new TestSuite(RecursiveActionTest.class)); |
115 |
> |
suite.addTest(new TestSuite(RecursiveTaskTest.class)); |
116 |
> |
suite.addTest(new TestSuite(LinkedTransferQueueTest.class)); |
117 |
> |
suite.addTest(new TestSuite(PhaserTest.class)); |
118 |
> |
suite.addTest(new TestSuite(ThreadLocalRandomTest.class)); |
119 |
|
suite.addTest(new TestSuite(AbstractExecutorServiceTest.class)); |
120 |
+ |
suite.addTest(new TestSuite(AbstractQueueTest.class)); |
121 |
|
suite.addTest(new TestSuite(AbstractQueuedSynchronizerTest.class)); |
122 |
+ |
suite.addTest(new TestSuite(AbstractQueuedLongSynchronizerTest.class)); |
123 |
|
suite.addTest(new TestSuite(ArrayBlockingQueueTest.class)); |
124 |
< |
suite.addTest(new TestSuite(AtomicBooleanTest.class)); |
125 |
< |
suite.addTest(new TestSuite(AtomicIntegerArrayTest.class)); |
126 |
< |
suite.addTest(new TestSuite(AtomicIntegerFieldUpdaterTest.class)); |
127 |
< |
suite.addTest(new TestSuite(AtomicIntegerTest.class)); |
128 |
< |
suite.addTest(new TestSuite(AtomicLongArrayTest.class)); |
129 |
< |
suite.addTest(new TestSuite(AtomicLongFieldUpdaterTest.class)); |
130 |
< |
suite.addTest(new TestSuite(AtomicLongTest.class)); |
131 |
< |
suite.addTest(new TestSuite(AtomicMarkableReferenceTest.class)); |
132 |
< |
suite.addTest(new TestSuite(AtomicReferenceArrayTest.class)); |
133 |
< |
suite.addTest(new TestSuite(AtomicReferenceFieldUpdaterTest.class)); |
134 |
< |
suite.addTest(new TestSuite(AtomicReferenceTest.class)); |
135 |
< |
suite.addTest(new TestSuite(AtomicStampedReferenceTest.class)); |
124 |
> |
suite.addTest(new TestSuite(ArrayDequeTest.class)); |
125 |
> |
suite.addTest(new TestSuite(AtomicBooleanTest.class)); |
126 |
> |
suite.addTest(new TestSuite(AtomicIntegerArrayTest.class)); |
127 |
> |
suite.addTest(new TestSuite(AtomicIntegerFieldUpdaterTest.class)); |
128 |
> |
suite.addTest(new TestSuite(AtomicIntegerTest.class)); |
129 |
> |
suite.addTest(new TestSuite(AtomicLongArrayTest.class)); |
130 |
> |
suite.addTest(new TestSuite(AtomicLongFieldUpdaterTest.class)); |
131 |
> |
suite.addTest(new TestSuite(AtomicLongTest.class)); |
132 |
> |
suite.addTest(new TestSuite(AtomicMarkableReferenceTest.class)); |
133 |
> |
suite.addTest(new TestSuite(AtomicReferenceArrayTest.class)); |
134 |
> |
suite.addTest(new TestSuite(AtomicReferenceFieldUpdaterTest.class)); |
135 |
> |
suite.addTest(new TestSuite(AtomicReferenceTest.class)); |
136 |
> |
suite.addTest(new TestSuite(AtomicStampedReferenceTest.class)); |
137 |
|
suite.addTest(new TestSuite(ConcurrentHashMapTest.class)); |
138 |
|
suite.addTest(new TestSuite(ConcurrentLinkedQueueTest.class)); |
139 |
+ |
suite.addTest(new TestSuite(ConcurrentSkipListMapTest.class)); |
140 |
+ |
suite.addTest(new TestSuite(ConcurrentSkipListSubMapTest.class)); |
141 |
+ |
suite.addTest(new TestSuite(ConcurrentSkipListSetTest.class)); |
142 |
+ |
suite.addTest(new TestSuite(ConcurrentSkipListSubSetTest.class)); |
143 |
|
suite.addTest(new TestSuite(CopyOnWriteArrayListTest.class)); |
144 |
|
suite.addTest(new TestSuite(CopyOnWriteArraySetTest.class)); |
145 |
|
suite.addTest(new TestSuite(CountDownLatchTest.class)); |
146 |
|
suite.addTest(new TestSuite(CyclicBarrierTest.class)); |
147 |
|
suite.addTest(new TestSuite(DelayQueueTest.class)); |
148 |
+ |
suite.addTest(new TestSuite(EntryTest.class)); |
149 |
|
suite.addTest(new TestSuite(ExchangerTest.class)); |
150 |
|
suite.addTest(new TestSuite(ExecutorsTest.class)); |
151 |
|
suite.addTest(new TestSuite(ExecutorCompletionServiceTest.class)); |
152 |
|
suite.addTest(new TestSuite(FutureTaskTest.class)); |
153 |
+ |
suite.addTest(new TestSuite(LinkedBlockingDequeTest.class)); |
154 |
|
suite.addTest(new TestSuite(LinkedBlockingQueueTest.class)); |
155 |
|
suite.addTest(new TestSuite(LinkedListTest.class)); |
156 |
|
suite.addTest(new TestSuite(LockSupportTest.class)); |
159 |
|
suite.addTest(new TestSuite(ReentrantLockTest.class)); |
160 |
|
suite.addTest(new TestSuite(ReentrantReadWriteLockTest.class)); |
161 |
|
suite.addTest(new TestSuite(ScheduledExecutorTest.class)); |
162 |
+ |
suite.addTest(new TestSuite(ScheduledExecutorSubclassTest.class)); |
163 |
|
suite.addTest(new TestSuite(SemaphoreTest.class)); |
164 |
|
suite.addTest(new TestSuite(SynchronousQueueTest.class)); |
165 |
|
suite.addTest(new TestSuite(SystemTest.class)); |
166 |
|
suite.addTest(new TestSuite(ThreadLocalTest.class)); |
167 |
|
suite.addTest(new TestSuite(ThreadPoolExecutorTest.class)); |
168 |
+ |
suite.addTest(new TestSuite(ThreadPoolExecutorSubclassTest.class)); |
169 |
|
suite.addTest(new TestSuite(ThreadTest.class)); |
170 |
|
suite.addTest(new TestSuite(TimeUnitTest.class)); |
171 |
< |
|
171 |
> |
suite.addTest(new TestSuite(TreeMapTest.class)); |
172 |
> |
suite.addTest(new TestSuite(TreeSetTest.class)); |
173 |
> |
suite.addTest(new TestSuite(TreeSubMapTest.class)); |
174 |
> |
suite.addTest(new TestSuite(TreeSubSetTest.class)); |
175 |
> |
|
176 |
|
return suite; |
177 |
|
} |
178 |
|
|
184 |
|
|
185 |
|
|
186 |
|
/** |
187 |
< |
* Return the shortest timed delay. This could |
187 |
> |
* Returns the shortest timed delay. This could |
188 |
|
* be reimplemented to use for example a Property. |
189 |
< |
*/ |
189 |
> |
*/ |
190 |
|
protected long getShortDelay() { |
191 |
< |
return 100; |
191 |
> |
return 50; |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
|
/** |
196 |
< |
* Set delays as multiples of SHORT_DELAY. |
196 |
> |
* Sets delays as multiples of SHORT_DELAY. |
197 |
|
*/ |
198 |
|
protected void setDelays() { |
199 |
|
SHORT_DELAY_MS = getShortDelay(); |
208 |
|
volatile boolean threadFailed; |
209 |
|
|
210 |
|
/** |
211 |
< |
* Initialize test to indicate that no thread assertions have failed |
211 |
> |
* Initializes test to indicate that no thread assertions have failed |
212 |
|
*/ |
213 |
< |
public void setUp() { |
213 |
> |
public void setUp() { |
214 |
|
setDelays(); |
215 |
< |
threadFailed = false; |
215 |
> |
threadFailed = false; |
216 |
|
} |
217 |
|
|
218 |
|
/** |
219 |
< |
* Trigger test case failure if any thread assertions have failed |
219 |
> |
* Triggers test case failure if any thread assertions have failed |
220 |
|
*/ |
221 |
< |
public void tearDown() { |
222 |
< |
assertFalse(threadFailed); |
221 |
> |
public void tearDown() { |
222 |
> |
assertFalse(threadFailed); |
223 |
|
} |
224 |
|
|
225 |
|
/** |
226 |
|
* Fail, also setting status to indicate current testcase should fail |
227 |
< |
*/ |
227 |
> |
*/ |
228 |
|
public void threadFail(String reason) { |
229 |
|
threadFailed = true; |
230 |
|
fail(reason); |
233 |
|
/** |
234 |
|
* If expression not true, set status to indicate current testcase |
235 |
|
* should fail |
236 |
< |
*/ |
236 |
> |
*/ |
237 |
|
public void threadAssertTrue(boolean b) { |
238 |
|
if (!b) { |
239 |
|
threadFailed = true; |
244 |
|
/** |
245 |
|
* If expression not false, set status to indicate current testcase |
246 |
|
* should fail |
247 |
< |
*/ |
247 |
> |
*/ |
248 |
|
public void threadAssertFalse(boolean b) { |
249 |
|
if (b) { |
250 |
|
threadFailed = true; |
255 |
|
/** |
256 |
|
* If argument not null, set status to indicate current testcase |
257 |
|
* should fail |
258 |
< |
*/ |
258 |
> |
*/ |
259 |
|
public void threadAssertNull(Object x) { |
260 |
|
if (x != null) { |
261 |
|
threadFailed = true; |
266 |
|
/** |
267 |
|
* If arguments not equal, set status to indicate current testcase |
268 |
|
* should fail |
269 |
< |
*/ |
269 |
> |
*/ |
270 |
|
public void threadAssertEquals(long x, long y) { |
271 |
|
if (x != y) { |
272 |
|
threadFailed = true; |
277 |
|
/** |
278 |
|
* If arguments not equal, set status to indicate current testcase |
279 |
|
* should fail |
280 |
< |
*/ |
280 |
> |
*/ |
281 |
|
public void threadAssertEquals(Object x, Object y) { |
282 |
|
if (x != y && (x == null || !x.equals(y))) { |
283 |
|
threadFailed = true; |
287 |
|
|
288 |
|
/** |
289 |
|
* threadFail with message "should throw exception" |
290 |
< |
*/ |
290 |
> |
*/ |
291 |
|
public void threadShouldThrow() { |
292 |
< |
threadFailed = true; |
293 |
< |
fail("should throw exception"); |
292 |
> |
try { |
293 |
> |
threadFailed = true; |
294 |
> |
fail("should throw exception"); |
295 |
> |
} catch (AssertionFailedError e) { |
296 |
> |
e.printStackTrace(); |
297 |
> |
throw e; |
298 |
> |
} |
299 |
|
} |
300 |
|
|
301 |
|
/** |
306 |
|
fail("Unexpected exception"); |
307 |
|
} |
308 |
|
|
309 |
+ |
/** |
310 |
+ |
* threadFail with message "Unexpected exception", with argument |
311 |
+ |
*/ |
312 |
+ |
public void threadUnexpectedException(Throwable ex) { |
313 |
+ |
threadFailed = true; |
314 |
+ |
ex.printStackTrace(); |
315 |
+ |
fail("Unexpected exception: " + ex); |
316 |
+ |
} |
317 |
|
|
318 |
|
/** |
319 |
|
* Wait out termination of a thread pool or fail doing so |
321 |
|
public void joinPool(ExecutorService exec) { |
322 |
|
try { |
323 |
|
exec.shutdown(); |
324 |
< |
assertTrue(exec.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
325 |
< |
} catch(InterruptedException ie) { |
324 |
> |
assertTrue(exec.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); |
325 |
> |
} catch (SecurityException ok) { |
326 |
> |
// Allowed in case test doesn't have privs |
327 |
> |
} catch (InterruptedException ie) { |
328 |
|
fail("Unexpected exception"); |
329 |
|
} |
330 |
|
} |
332 |
|
|
333 |
|
/** |
334 |
|
* fail with message "should throw exception" |
335 |
< |
*/ |
335 |
> |
*/ |
336 |
|
public void shouldThrow() { |
337 |
|
fail("Should throw exception"); |
338 |
|
} |
344 |
|
fail("Unexpected exception"); |
345 |
|
} |
346 |
|
|
347 |
+ |
/** |
348 |
+ |
* fail with message "Unexpected exception", with argument |
349 |
+ |
*/ |
350 |
+ |
public void unexpectedException(Throwable ex) { |
351 |
+ |
ex.printStackTrace(); |
352 |
+ |
fail("Unexpected exception: " + ex); |
353 |
+ |
} |
354 |
+ |
|
355 |
|
|
356 |
|
/** |
357 |
|
* The number of elements to place in collections, arrays, etc. |
375 |
|
static final Integer m3 = new Integer(-3); |
376 |
|
static final Integer m4 = new Integer(-4); |
377 |
|
static final Integer m5 = new Integer(-5); |
378 |
+ |
static final Integer m6 = new Integer(-6); |
379 |
|
static final Integer m10 = new Integer(-10); |
380 |
|
|
381 |
|
|
403 |
|
|
404 |
|
// Some convenient Runnable classes |
405 |
|
|
406 |
+ |
abstract class CheckedRunnable implements Runnable { |
407 |
+ |
abstract void realRun() throws Throwable; |
408 |
+ |
|
409 |
+ |
public final void run() { |
410 |
+ |
try { |
411 |
+ |
realRun(); |
412 |
+ |
} catch (Throwable t) { |
413 |
+ |
threadUnexpectedException(t); |
414 |
+ |
} |
415 |
+ |
} |
416 |
+ |
} |
417 |
+ |
|
418 |
+ |
abstract class CheckedInterruptedRunnable implements Runnable { |
419 |
+ |
abstract void realRun() throws Throwable; |
420 |
+ |
|
421 |
+ |
public final void run() { |
422 |
+ |
try { |
423 |
+ |
realRun(); |
424 |
+ |
threadShouldThrow(); |
425 |
+ |
} catch (InterruptedException success) { |
426 |
+ |
} catch (Throwable t) { |
427 |
+ |
threadUnexpectedException(t); |
428 |
+ |
} |
429 |
+ |
} |
430 |
+ |
} |
431 |
+ |
|
432 |
+ |
abstract class CheckedCallable<T> implements Callable<T> { |
433 |
+ |
abstract T realCall() throws Throwable; |
434 |
+ |
|
435 |
+ |
public final T call() { |
436 |
+ |
try { |
437 |
+ |
return realCall(); |
438 |
+ |
} catch (Throwable t) { |
439 |
+ |
threadUnexpectedException(t); |
440 |
+ |
return null; |
441 |
+ |
} |
442 |
+ |
} |
443 |
+ |
} |
444 |
+ |
|
445 |
|
static class NoOpRunnable implements Runnable { |
446 |
|
public void run() {} |
447 |
|
} |
464 |
|
public Integer call() { return one; } |
465 |
|
} |
466 |
|
|
467 |
< |
class ShortRunnable implements Runnable { |
468 |
< |
public void run() { |
469 |
< |
try { |
375 |
< |
Thread.sleep(SHORT_DELAY_MS); |
376 |
< |
} |
377 |
< |
catch(Exception e) { |
378 |
< |
threadUnexpectedException(); |
379 |
< |
} |
467 |
> |
class ShortRunnable extends CheckedRunnable { |
468 |
> |
void realRun() throws Throwable { |
469 |
> |
Thread.sleep(SHORT_DELAY_MS); |
470 |
|
} |
471 |
|
} |
472 |
|
|
473 |
< |
class ShortInterruptedRunnable implements Runnable { |
474 |
< |
public void run() { |
475 |
< |
try { |
386 |
< |
Thread.sleep(SHORT_DELAY_MS); |
387 |
< |
threadShouldThrow(); |
388 |
< |
} |
389 |
< |
catch(InterruptedException success) { |
390 |
< |
} |
473 |
> |
class ShortInterruptedRunnable extends CheckedInterruptedRunnable { |
474 |
> |
void realRun() throws InterruptedException { |
475 |
> |
Thread.sleep(SHORT_DELAY_MS); |
476 |
|
} |
477 |
|
} |
478 |
|
|
479 |
< |
class SmallRunnable implements Runnable { |
480 |
< |
public void run() { |
481 |
< |
try { |
397 |
< |
Thread.sleep(SMALL_DELAY_MS); |
398 |
< |
} |
399 |
< |
catch(Exception e) { |
400 |
< |
threadUnexpectedException(); |
401 |
< |
} |
479 |
> |
class SmallRunnable extends CheckedRunnable { |
480 |
> |
void realRun() throws Throwable { |
481 |
> |
Thread.sleep(SMALL_DELAY_MS); |
482 |
|
} |
483 |
|
} |
484 |
|
|
485 |
< |
class SmallPossiblyInterruptedRunnable implements Runnable { |
486 |
< |
public void run() { |
485 |
> |
class SmallPossiblyInterruptedRunnable extends CheckedRunnable { |
486 |
> |
void realRun() { |
487 |
|
try { |
488 |
|
Thread.sleep(SMALL_DELAY_MS); |
489 |
|
} |
490 |
< |
catch(Exception e) { |
490 |
> |
catch (InterruptedException ok) { |
491 |
|
} |
492 |
|
} |
493 |
|
} |
494 |
|
|
495 |
< |
class SmallCallable implements Callable { |
496 |
< |
public Object call() { |
497 |
< |
try { |
418 |
< |
Thread.sleep(SMALL_DELAY_MS); |
419 |
< |
} |
420 |
< |
catch(Exception e) { |
421 |
< |
threadUnexpectedException(); |
422 |
< |
} |
495 |
> |
class SmallCallable extends CheckedCallable { |
496 |
> |
Object realCall() throws Throwable { |
497 |
> |
Thread.sleep(SMALL_DELAY_MS); |
498 |
|
return Boolean.TRUE; |
499 |
|
} |
500 |
|
} |
501 |
|
|
502 |
< |
class SmallInterruptedRunnable implements Runnable { |
503 |
< |
public void run() { |
504 |
< |
try { |
430 |
< |
Thread.sleep(SMALL_DELAY_MS); |
431 |
< |
threadShouldThrow(); |
432 |
< |
} |
433 |
< |
catch(InterruptedException success) { |
434 |
< |
} |
502 |
> |
class SmallInterruptedRunnable extends CheckedInterruptedRunnable { |
503 |
> |
void realRun() throws InterruptedException { |
504 |
> |
Thread.sleep(SMALL_DELAY_MS); |
505 |
|
} |
506 |
|
} |
507 |
|
|
508 |
< |
|
509 |
< |
class MediumRunnable implements Runnable { |
510 |
< |
public void run() { |
441 |
< |
try { |
442 |
< |
Thread.sleep(MEDIUM_DELAY_MS); |
443 |
< |
} |
444 |
< |
catch(Exception e) { |
445 |
< |
threadUnexpectedException(); |
446 |
< |
} |
508 |
> |
class MediumRunnable extends CheckedRunnable { |
509 |
> |
void realRun() throws Throwable { |
510 |
> |
Thread.sleep(MEDIUM_DELAY_MS); |
511 |
|
} |
512 |
|
} |
513 |
|
|
514 |
< |
class MediumInterruptedRunnable implements Runnable { |
515 |
< |
public void run() { |
516 |
< |
try { |
453 |
< |
Thread.sleep(MEDIUM_DELAY_MS); |
454 |
< |
threadShouldThrow(); |
455 |
< |
} |
456 |
< |
catch(InterruptedException success) { |
457 |
< |
} |
514 |
> |
class MediumInterruptedRunnable extends CheckedInterruptedRunnable { |
515 |
> |
void realRun() throws InterruptedException { |
516 |
> |
Thread.sleep(MEDIUM_DELAY_MS); |
517 |
|
} |
518 |
|
} |
519 |
|
|
520 |
< |
class MediumPossiblyInterruptedRunnable implements Runnable { |
521 |
< |
public void run() { |
520 |
> |
class MediumPossiblyInterruptedRunnable extends CheckedRunnable { |
521 |
> |
void realRun() { |
522 |
|
try { |
523 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
524 |
|
} |
525 |
< |
catch(InterruptedException success) { |
525 |
> |
catch (InterruptedException ok) { |
526 |
|
} |
527 |
|
} |
528 |
|
} |
529 |
|
|
530 |
< |
class LongPossiblyInterruptedRunnable implements Runnable { |
531 |
< |
public void run() { |
530 |
> |
class LongPossiblyInterruptedRunnable extends CheckedRunnable { |
531 |
> |
void realRun() { |
532 |
|
try { |
533 |
|
Thread.sleep(LONG_DELAY_MS); |
534 |
|
} |
535 |
< |
catch(InterruptedException success) { |
535 |
> |
catch (InterruptedException ok) { |
536 |
|
} |
537 |
|
} |
538 |
|
} |
540 |
|
/** |
541 |
|
* For use as ThreadFactory in constructors |
542 |
|
*/ |
543 |
< |
static class SimpleThreadFactory implements ThreadFactory{ |
544 |
< |
public Thread newThread(Runnable r){ |
543 |
> |
static class SimpleThreadFactory implements ThreadFactory { |
544 |
> |
public Thread newThread(Runnable r) { |
545 |
|
return new Thread(r); |
546 |
< |
} |
546 |
> |
} |
547 |
|
} |
548 |
|
|
549 |
|
static class TrackedShortRunnable implements Runnable { |
552 |
|
try { |
553 |
|
Thread.sleep(SMALL_DELAY_MS); |
554 |
|
done = true; |
555 |
< |
} catch(Exception e){ |
555 |
> |
} catch (Exception e) { |
556 |
|
} |
557 |
|
} |
558 |
|
} |
563 |
|
try { |
564 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
565 |
|
done = true; |
566 |
< |
} catch(Exception e){ |
566 |
> |
} catch (Exception e) { |
567 |
|
} |
568 |
|
} |
569 |
|
} |
574 |
|
try { |
575 |
|
Thread.sleep(LONG_DELAY_MS); |
576 |
|
done = true; |
577 |
< |
} catch(Exception e){ |
577 |
> |
} catch (Exception e) { |
578 |
|
} |
579 |
|
} |
580 |
|
} |
592 |
|
try { |
593 |
|
Thread.sleep(SMALL_DELAY_MS); |
594 |
|
done = true; |
595 |
< |
} catch(Exception e){ |
595 |
> |
} catch (Exception e) { |
596 |
|
} |
597 |
|
return Boolean.TRUE; |
598 |
|
} |
602 |
|
/** |
603 |
|
* For use as RejectedExecutionHandler in constructors |
604 |
|
*/ |
605 |
< |
static class NoOpREHandler implements RejectedExecutionHandler{ |
606 |
< |
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor){} |
605 |
> |
static class NoOpREHandler implements RejectedExecutionHandler { |
606 |
> |
public void rejectedExecution(Runnable r, |
607 |
> |
ThreadPoolExecutor executor) {} |
608 |
|
} |
609 |
< |
|
550 |
< |
|
609 |
> |
|
610 |
|
} |