ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/JSR166TestCase.java
(Generate patch)

Comparing jsr166/src/test/tck/JSR166TestCase.java (file contents):
Revision 1.267 by jsr166, Sun Sep 8 16:08:56 2019 UTC vs.
Revision 1.268 by jsr166, Sun Sep 22 01:59:57 2019 UTC

# Line 49 | Line 49 | import java.io.ByteArrayOutputStream;
49   import java.io.ObjectInputStream;
50   import java.io.ObjectOutputStream;
51   import java.lang.management.ManagementFactory;
52 + import java.lang.management.LockInfo;
53   import java.lang.management.ThreadInfo;
54   import java.lang.management.ThreadMXBean;
55   import java.lang.reflect.Constructor;
# Line 243 | Line 244 | public class JSR166TestCase extends Test
244          }
245      }
246  
247 +    private static final ThreadMXBean THREAD_MXBEAN
248 +        = ManagementFactory.getThreadMXBean();
249 +
250      /**
251       * The scaling factor to apply to standard delays used in tests.
252       * May be initialized from any of:
# Line 1130 | Line 1134 | public class JSR166TestCase extends Test
1134              }
1135          }
1136  
1133        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
1137          System.err.println("------ stacktrace dump start ------");
1138 <        for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true))
1138 >        for (ThreadInfo info : THREAD_MXBEAN.dumpAllThreads(true, true))
1139              if (threadOfInterest(info))
1140                  System.err.print(info);
1141          System.err.println("------ stacktrace dump end ------");
# Line 1161 | Line 1164 | public class JSR166TestCase extends Test
1164      }
1165  
1166      /**
1167 +     * Returns the thread's blocker's class name, if any, else null.
1168 +     */
1169 +    String blockerClassName(Thread thread) {
1170 +        ThreadInfo threadInfo; LockInfo lockInfo;
1171 +        if ((threadInfo = THREAD_MXBEAN.getThreadInfo(thread.getId(), 0)) != null
1172 +            && (lockInfo = threadInfo.getLockInfo()) != null)
1173 +            return lockInfo.getClassName();
1174 +        return null;
1175 +    }
1176 +
1177 +    /**
1178       * Checks that future.get times out, with the default timeout of
1179       * {@code timeoutMillis()}.
1180       */
# Line 1459 | Line 1473 | public class JSR166TestCase extends Test
1473      }
1474  
1475      /**
1476 +     * Returns a new started daemon Thread running the given action,
1477 +     * wrapped in a CheckedRunnable.
1478 +     */
1479 +    Thread newStartedThread(Action action) {
1480 +        return newStartedThread(checkedRunnable(action));
1481 +    }
1482 +
1483 +    /**
1484       * Waits for the specified time (in milliseconds) for the thread
1485       * to terminate (using {@link Thread#join(long)}), else interrupts
1486       * the thread (in the hope that it may terminate later) and fails.
# Line 1505 | Line 1527 | public class JSR166TestCase extends Test
1527          }
1528      }
1529  
1530 +    Runnable checkedRunnable(Action action) {
1531 +        return new CheckedRunnable() {
1532 +            public void realRun() throws Throwable {
1533 +                action.run();
1534 +            }};
1535 +    }
1536 +
1537      public abstract class ThreadShouldThrow extends Thread {
1538          protected abstract void realRun() throws Throwable;
1539  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines