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; |
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: |
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 ------"); |
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 |
|
*/ |
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. |
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 |
|
|