40 |
|
import java.util.concurrent.ExecutionException; |
41 |
|
import java.util.concurrent.Executors; |
42 |
|
import java.util.concurrent.ExecutorService; |
43 |
+ |
import java.util.concurrent.ForkJoinPool; |
44 |
|
import java.util.concurrent.Future; |
45 |
|
import java.util.concurrent.RecursiveAction; |
46 |
|
import java.util.concurrent.RecursiveTask; |
522 |
|
setDelays(); |
523 |
|
} |
524 |
|
|
525 |
+ |
void tearDownFail(String format, Object... args) { |
526 |
+ |
String msg = toString() + ": " + String.format(format, args); |
527 |
+ |
System.err.println(msg); |
528 |
+ |
printAllStackTraces(); |
529 |
+ |
throw new AssertionFailedError(msg); |
530 |
+ |
} |
531 |
+ |
|
532 |
|
/** |
533 |
|
* Extra checks that get done for all test cases. |
534 |
|
* |
556 |
|
} |
557 |
|
|
558 |
|
if (Thread.interrupted()) |
559 |
< |
throw new AssertionFailedError("interrupt status set in main thread"); |
559 |
> |
tearDownFail("interrupt status set in main thread"); |
560 |
|
|
561 |
|
checkForkJoinPoolThreadLeaks(); |
562 |
|
} |
565 |
|
* Finds missing try { ... } finally { joinPool(e); } |
566 |
|
*/ |
567 |
|
void checkForkJoinPoolThreadLeaks() throws InterruptedException { |
568 |
< |
Thread[] survivors = new Thread[5]; |
568 |
> |
Thread[] survivors = new Thread[7]; |
569 |
|
int count = Thread.enumerate(survivors); |
570 |
|
for (int i = 0; i < count; i++) { |
571 |
|
Thread thread = survivors[i]; |
573 |
|
if (name.startsWith("ForkJoinPool-")) { |
574 |
|
// give thread some time to terminate |
575 |
|
thread.join(LONG_DELAY_MS); |
576 |
< |
if (!thread.isAlive()) continue; |
577 |
< |
throw new AssertionFailedError |
578 |
< |
(String.format("Found leaked ForkJoinPool thread test=%s thread=%s%n", |
571 |
< |
toString(), name)); |
576 |
> |
if (thread.isAlive()) |
577 |
> |
tearDownFail("Found leaked ForkJoinPool thread thread=%s", |
578 |
> |
thread); |
579 |
|
} |
580 |
|
} |
581 |
+ |
|
582 |
+ |
if (!ForkJoinPool.commonPool() |
583 |
+ |
.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)) |
584 |
+ |
tearDownFail("ForkJoin common pool thread stuck"); |
585 |
|
} |
586 |
|
|
587 |
|
/** |