--- jsr166/src/test/tck/JSR166TestCase.java 2015/10/03 16:57:25 1.149 +++ jsr166/src/test/tck/JSR166TestCase.java 2015/10/03 19:39:16 1.154 @@ -15,6 +15,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; +import java.lang.management.ThreadMXBean; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -518,6 +519,7 @@ public class JSR166TestCase extends Test * the same test have no effect. */ public void threadRecordFailure(Throwable t) { + threadDump(); threadFailure.compareAndSet(null, t); } @@ -528,7 +530,7 @@ public class JSR166TestCase extends Test void tearDownFail(String format, Object... args) { String msg = toString() + ": " + String.format(format, args); System.err.println(msg); - printAllStackTraces(); + threadDump(); throw new AssertionFailedError(msg); } @@ -597,7 +599,7 @@ public class JSR166TestCase extends Test fail(reason); } catch (AssertionFailedError t) { threadRecordFailure(t); - fail(reason); + throw t; } } @@ -777,8 +779,9 @@ public class JSR166TestCase extends Test * necessarily individually slow because they must block. */ void testInParallel(Action ... actions) { - ExecutorService pool = Executors.newCachedThreadPool(); - try { + try (PoolCloser poolCloser + = new PoolCloser<>(Executors.newCachedThreadPool())) { + ExecutorService pool = poolCloser.pool; ArrayList> futures = new ArrayList<>(actions.length); for (final Action action : actions) futures.add(pool.submit(new CheckedRunnable() { @@ -791,19 +794,29 @@ public class JSR166TestCase extends Test } catch (Exception ex) { threadUnexpectedException(ex); } - } finally { - joinPool(pool); } } /** * A debugging tool to print all stack traces, as jstack does. + * Uninteresting threads are filtered out. */ - static void printAllStackTraces() { - for (ThreadInfo info : - ManagementFactory.getThreadMXBean() - .dumpAllThreads(true, true)) + static void threadDump() { + ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); + System.err.println("------ stacktrace dump start ------"); + for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) { + String name = info.getThreadName(); + if ("Signal Dispatcher".equals(name)) + continue; + if ("Reference Handler".equals(name) + && info.getLockName().startsWith("java.lang.ref.Reference$Lock")) + continue; + if ("Finalizer".equals(name) + && info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock")) + continue; System.err.print(info); + } + System.err.println("------ stacktrace dump end ------"); } /**