public class ThreadDump extends Object
Intended for unit and integration test assertions to detect stray threads and should not be used on hot paths as the checks are relatively expensive.
Provides functionality for collecting stack traces of threads and detecting unexpected thread creation, which can be useful in testing and debugging scenarios.
| Modifier and Type | Field and Description |
|---|---|
static String |
IGNORE_THREAD_IF_IN_NAME |
| Constructor and Description |
|---|
ThreadDump()
Constructs a ThreadDump instance, initializing the set of threads
at the time of creation.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
add(Thread t,
StackTrace stackTrace)
Adds a thread with its stack trace to the map of monitored threads.
|
void |
assertNoNewThreads()
Fail if any new threads still exist after an adaptive wait.
|
void |
assertNoNewThreads(int delay,
@NotNull TimeUnit delayUnit)
Fail if any new threads remain after a supplied delay.
|
static StackTrace |
createdHereFor(Thread thread)
Retrieves the stack trace for a given thread.
|
void |
ignore(String threadName)
Marks a thread to be ignored by the
assertNoNewThreads() check. |
public static final String IGNORE_THREAD_IF_IN_NAME
public ThreadDump()
public static void add(Thread t, StackTrace stackTrace)
t - the thread to be monitoredstackTrace - the stack trace of the threadpublic static StackTrace createdHereFor(Thread thread)
thread - the thread whose stack trace is to be retrievedpublic void ignore(String threadName)
assertNoNewThreads() check.threadName - the name of the thread to be ignoredpublic void assertNoNewThreads()
The initial set of threads is captured when this object is constructed. The method waits in a loop with exponentially increasing pauses to give short-lived threads time to finish.
public void assertNoNewThreads(int delay,
@NotNull
@NotNull TimeUnit delayUnit)
The wait is adaptive: up to fourteen iterations (eighteen on ARM) are
performed, each pausing for delay divided across the loop plus an
exponential back-off of 1L << (i/2) milliseconds. Longer delays on
ARM compensate for slower context switching.
delay - total extra time to wait across all iterationsdelayUnit - unit of delayCopyright © 2026 Chronicle Software Ltd. All rights reserved.