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