384 |
|
|
385 |
|
if (Thread.interrupted()) |
386 |
|
throw new AssertionFailedError("interrupt status set in main thread"); |
387 |
+ |
|
388 |
+ |
checkForkJoinPoolThreadLeaks(); |
389 |
|
} |
390 |
|
|
391 |
|
/** |
392 |
+ |
* Find missing try { ... } finally { joinPool(e); } |
393 |
+ |
*/ |
394 |
+ |
void checkForkJoinPoolThreadLeaks() throws InterruptedException { |
395 |
+ |
Thread[] survivors = new Thread[5]; |
396 |
+ |
int count = Thread.enumerate(survivors); |
397 |
+ |
for (int i = 0; i < count; i++) { |
398 |
+ |
Thread thread = survivors[i]; |
399 |
+ |
String name = thread.getName(); |
400 |
+ |
if (name.startsWith("ForkJoinPool-")) { |
401 |
+ |
// give thread some time to terminate |
402 |
+ |
thread.join(LONG_DELAY_MS); |
403 |
+ |
if (!thread.isAlive()) continue; |
404 |
+ |
thread.stop(); |
405 |
+ |
throw new AssertionFailedError |
406 |
+ |
(String.format("Found leaked ForkJoinPool thread test=%s thread=%s%n", |
407 |
+ |
toString(), name)); |
408 |
+ |
} |
409 |
+ |
} |
410 |
+ |
} |
411 |
+ |
|
412 |
+ |
/** |
413 |
|
* Just like fail(reason), but additionally recording (using |
414 |
|
* threadRecordFailure) any AssertionFailedError thrown, so that |
415 |
|
* the current testcase will fail. |