|
2 | 2 |
|
3 | 3 | import static java.lang.Thread.currentThread; |
4 | 4 |
|
5 | | -import java.io.FileWriter; |
6 | 5 | import java.io.IOException; |
7 | | -import java.io.PrintWriter; |
8 | 6 | import java.lang.management.ManagementFactory; |
9 | 7 | import java.lang.management.ThreadInfo; |
10 | 8 | import java.lang.management.ThreadMXBean; |
11 | 9 | import java.nio.ByteBuffer; |
12 | 10 | import java.nio.channels.SelectionKey; |
13 | 11 | import java.nio.channels.Selector; |
14 | 12 | import java.nio.channels.SocketChannel; |
15 | | -import java.text.SimpleDateFormat; |
16 | | -import java.util.Date; |
17 | 13 | import java.util.Iterator; |
18 | 14 |
|
19 | 15 | import org.jboss.logging.Logger; |
@@ -176,22 +172,22 @@ public static void threadDump() throws IOException { |
176 | 172 |
|
177 | 173 | // Create a PrintWriter to write the thread dump to a file |
178 | 174 | //try (PrintWriter writer = new PrintWriter(new FileWriter(fileName))) { |
179 | | - // Get the ThreadMXBean instance |
180 | | - ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); |
181 | | - |
182 | | - // Get all thread IDs |
183 | | - long[] threadIds = threadMXBean.getAllThreadIds(); |
184 | | - ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadIds, Integer.MAX_VALUE); |
185 | | - |
186 | | - // Write the thread information to the file |
187 | | - for (ThreadInfo threadInfo : threadInfos) { |
188 | | - threadDumpStr += "Thread ID: " + threadInfo.getThreadId() + " Name: " + threadInfo.getThreadName() + "\n"; |
189 | | - threadDumpStr += "Thread State: " + threadInfo.getThreadState() + "\n"; |
190 | | - StackTraceElement[] stackTrace = threadInfo.getStackTrace(); |
191 | | - for (StackTraceElement stackTraceElement : stackTrace) { |
192 | | - threadDumpStr += "\t" + stackTraceElement + "\n"; |
193 | | - } |
| 175 | + // Get the ThreadMXBean instance |
| 176 | + ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); |
| 177 | + |
| 178 | + // Get all thread IDs |
| 179 | + long[] threadIds = threadMXBean.getAllThreadIds(); |
| 180 | + ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadIds, Integer.MAX_VALUE); |
| 181 | + |
| 182 | + // Write the thread information to the file |
| 183 | + for (ThreadInfo threadInfo : threadInfos) { |
| 184 | + threadDumpStr += "Thread ID: " + threadInfo.getThreadId() + " Name: " + threadInfo.getThreadName() + "\n"; |
| 185 | + threadDumpStr += "Thread State: " + threadInfo.getThreadState() + "\n"; |
| 186 | + StackTraceElement[] stackTrace = threadInfo.getStackTrace(); |
| 187 | + for (StackTraceElement stackTraceElement : stackTrace) { |
| 188 | + threadDumpStr += "\t" + stackTraceElement + "\n"; |
194 | 189 | } |
| 190 | + } |
195 | 191 | //} |
196 | 192 |
|
197 | 193 | LOG.infof(threadDumpStr); |
|
0 commit comments