public class ThreadDump extends Object
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()
Asserts that no new threads are running beyond the ones that existed at the time
this ThreadDump instance was created.
|
void |
assertNoNewThreads(int delay,
@NotNull TimeUnit delayUnit)
Asserts that no new threads are running beyond the ones that existed at the time
this ThreadDump instance was created.
|
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()
This method can be used in testing scenarios to ensure that no unexpected threads have been left running.
public void assertNoNewThreads(int delay, @NotNull @NotNull TimeUnit delayUnit)
delay
- the extra time to wait for threads to terminatedelayUnit
- the time unit of the delay parameterCopyright © 2023. All rights reserved.