201 |
|
("Looks like we're stuck running test: " |
202 |
|
+ lastTestCase); |
203 |
|
dumpTestThreads(); |
204 |
+ |
// one stack dump is probably enough; more would be spam |
205 |
+ |
break; |
206 |
|
} |
207 |
|
lastTestCase = currentTestCase; |
208 |
|
}}}; |
592 |
|
} |
593 |
|
|
594 |
|
/** |
595 |
< |
* Finds missing try { ... } finally { joinPool(e); } |
595 |
> |
* Finds missing PoolCleaners |
596 |
|
*/ |
597 |
|
void checkForkJoinPoolThreadLeaks() throws InterruptedException { |
598 |
|
Thread[] survivors = new Thread[7]; |
776 |
|
public void close() { joinPool(pool); } |
777 |
|
} |
778 |
|
|
779 |
+ |
/** |
780 |
+ |
* An extension of PoolCleaner that has an action to release the pool. |
781 |
+ |
*/ |
782 |
+ |
class PoolCleanerWithReleaser extends PoolCleaner { |
783 |
+ |
private final Runnable releaser; |
784 |
+ |
public PoolCleanerWithReleaser(ExecutorService pool, Runnable releaser) { |
785 |
+ |
super(pool); |
786 |
+ |
this.releaser = releaser; |
787 |
+ |
} |
788 |
+ |
public void close() { |
789 |
+ |
try { |
790 |
+ |
releaser.run(); |
791 |
+ |
} finally { |
792 |
+ |
super.close(); |
793 |
+ |
} |
794 |
+ |
} |
795 |
+ |
} |
796 |
+ |
|
797 |
|
PoolCleaner cleaner(ExecutorService pool) { |
798 |
|
return new PoolCleaner(pool); |
799 |
|
} |
800 |
|
|
801 |
+ |
PoolCleaner cleaner(ExecutorService pool, Runnable releaser) { |
802 |
+ |
return new PoolCleanerWithReleaser(pool, releaser); |
803 |
+ |
} |
804 |
+ |
|
805 |
+ |
PoolCleaner cleaner(ExecutorService pool, CountDownLatch latch) { |
806 |
+ |
return new PoolCleanerWithReleaser(pool, releaser(latch)); |
807 |
+ |
} |
808 |
+ |
|
809 |
+ |
Runnable releaser(final CountDownLatch latch) { |
810 |
+ |
return new Runnable() { public void run() { |
811 |
+ |
do { latch.countDown(); } |
812 |
+ |
while (latch.getCount() > 0); |
813 |
+ |
}}; |
814 |
+ |
} |
815 |
+ |
|
816 |
|
/** |
817 |
|
* Waits out termination of a thread pool or fails doing so. |
818 |
|
*/ |