19 package org.sleuthkit.autopsy.coreutils;
21 import java.io.BufferedReader;
22 import java.io.StringReader;
23 import java.lang.management.ManagementFactory;
24 import java.lang.management.ThreadInfo;
25 import java.lang.management.ThreadMXBean;
26 import java.util.Arrays;
27 import java.util.concurrent.ExecutorService;
28 import java.util.concurrent.TimeUnit;
29 import java.util.stream.Collectors;
47 boolean tasksCompleted =
false;
48 while (!tasksCompleted) {
50 tasksCompleted = executor.awaitTermination(DEFAULT_TIMEOUT, DEFAULT_TIMEOUT_UNITS);
51 }
catch (InterruptedException ignored) {
68 StringBuilder threadDump =
new StringBuilder(System.lineSeparator());
69 ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
70 ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
71 for (ThreadInfo threadInfo : threadInfos) {
74 threadDump.append(
new BufferedReader(
new StringReader(threadInfo.toString()))
76 .collect(Collectors.joining(System.lineSeparator())));
77 threadDump.append(System.lineSeparator());
80 long[] deadlockThreadIds = threadMXBean.findDeadlockedThreads();
81 if (deadlockThreadIds != null) {
82 threadDump.append(
"-------------------List of Deadlocked Thread IDs ---------------------");
83 threadDump.append(System.lineSeparator());
84 String idsList = (Arrays
85 .stream(deadlockThreadIds)
87 .collect(Collectors.toList()))
88 .stream().map(n -> String.valueOf(n))
89 .collect(Collectors.joining(
"-",
"{",
"}"));
90 threadDump.append(idsList);
92 return threadDump.toString();
static String generateThreadDump()
static final TimeUnit DEFAULT_TIMEOUT_UNITS
static void shutDownTaskExecutor(ExecutorService executor)
static final long DEFAULT_TIMEOUT