Skip to content

Commit 18b2f77

Browse files
committed
Try printing thread dump info to log but with separate methods and additional logging.
1 parent f3fde3d commit 18b2f77

File tree

3 files changed

+8
-64
lines changed

3 files changed

+8
-64
lines changed

java-components/domain-proxy/client/src/main/java/com/redhat/hacbs/domainproxy/client/DomainProxyClient.java

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@
2020
import java.util.concurrent.ExecutorService;
2121
import java.util.concurrent.Executors;
2222

23+
import com.redhat.hacbs.domainproxy.common.CommonIOUtil;
2324
import jakarta.annotation.PostConstruct;
2425
import jakarta.annotation.PreDestroy;
2526
import jakarta.inject.Inject;
2627
import jakarta.inject.Singleton;
2728

2829
import org.eclipse.microprofile.config.inject.ConfigProperty;
2930

30-
import com.redhat.hacbs.domainproxy.common.CommonIOUtil;
31-
3231
import io.quarkus.logging.Log;
3332
import io.quarkus.runtime.Quarkus;
3433
import io.quarkus.runtime.Startup;
@@ -81,7 +80,7 @@ private void startClient() {
8180
executor.submit(channelToChannelBiDirectionalHandler(byteBufferSize, httpClientChannel,
8281
domainSocketChannel));
8382
Log.info("Before thread dump");
84-
threadDump();
83+
CommonIOUtil.threadDump();
8584
Log.info("After thread dump");
8685
}
8786
}
@@ -93,35 +92,6 @@ private void startClient() {
9392
Quarkus.asyncExit();
9493
}
9594

96-
private static void threadDump() throws IOException {
97-
// Create a timestamp with milliseconds for the file name
98-
//String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS").format(new Date());
99-
//String fileName = "/app/thread_dump_" + timestamp + ".txt";
100-
Log.info("Thread dump");
101-
String threadDumpStr = "";
102-
103-
// Create a PrintWriter to write the thread dump to a file
104-
//try (PrintWriter writer = new PrintWriter(new FileWriter(fileName))) {
105-
// Get the ThreadMXBean instance
106-
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
107-
108-
// Get all thread IDs
109-
long[] threadIds = threadMXBean.getAllThreadIds();
110-
ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadIds, Integer.MAX_VALUE);
111-
112-
// Write the thread information to the file
113-
for (ThreadInfo threadInfo : threadInfos) {
114-
threadDumpStr += "Thread ID: " + threadInfo.getThreadId() + " Name: " + threadInfo.getThreadName() + "\n";
115-
threadDumpStr += "Thread State: " + threadInfo.getThreadState() + "\n";
116-
StackTraceElement[] stackTrace = threadInfo.getStackTrace();
117-
for (StackTraceElement stackTraceElement : stackTrace) {
118-
threadDumpStr += "\t" + stackTraceElement + "\n";
119-
}
120-
}
121-
//}
122-
Log.info(threadDumpStr);
123-
}
124-
12595
@PreDestroy
12696
public void stop() {
12797
executor.shutdownNow();

java-components/domain-proxy/common/src/main/java/com/redhat/hacbs/domainproxy/common/CommonIOUtil.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public static void threadDump() throws IOException {
168168
// Create a timestamp with milliseconds for the file name
169169
//String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS").format(new Date());
170170
//String fileName = "/app/thread_dump_" + timestamp + ".txt";
171+
LOG.info("Thread dump");
171172
String threadDumpStr = "";
172173

173174
// Create a PrintWriter to write the thread dump to a file
@@ -181,10 +182,13 @@ public static void threadDump() throws IOException {
181182

182183
// Write the thread information to the file
183184
for (ThreadInfo threadInfo : threadInfos) {
185+
LOG.info("Thread ID: " + threadInfo.getThreadId() + " Name: " + threadInfo.getThreadName());
186+
LOG.info("Thread State: " + threadInfo.getThreadState());
184187
threadDumpStr += "Thread ID: " + threadInfo.getThreadId() + " Name: " + threadInfo.getThreadName() + "\n";
185188
threadDumpStr += "Thread State: " + threadInfo.getThreadState() + "\n";
186189
StackTraceElement[] stackTrace = threadInfo.getStackTrace();
187190
for (StackTraceElement stackTraceElement : stackTrace) {
191+
LOG.info("\t" + stackTraceElement);
188192
threadDumpStr += "\t" + stackTraceElement + "\n";
189193
}
190194
}

java-components/domain-proxy/server/src/main/java/com/redhat/hacbs/domainproxy/server/DomainProxyServer.java

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@
2222
import java.util.concurrent.ExecutorService;
2323
import java.util.concurrent.Executors;
2424

25+
import com.redhat.hacbs.domainproxy.common.CommonIOUtil;
2526
import jakarta.annotation.PostConstruct;
2627
import jakarta.annotation.PreDestroy;
2728
import jakarta.inject.Inject;
2829
import jakarta.inject.Singleton;
2930

3031
import org.eclipse.microprofile.config.inject.ConfigProperty;
3132

32-
import com.redhat.hacbs.domainproxy.common.CommonIOUtil;
33-
3433
import io.quarkus.logging.Log;
3534
import io.quarkus.runtime.Quarkus;
3635
import io.quarkus.runtime.Startup;
@@ -81,7 +80,7 @@ private void startServer() {
8180
executor.submit(channelToChannelBiDirectionalHandler(byteBufferSize, httpServerChannel,
8281
domainSocketChannel));
8382
Log.info("Before thread dump");
84-
threadDump();
83+
CommonIOUtil.threadDump();
8584
Log.info("After thread dump");
8685
}
8786
}
@@ -93,35 +92,6 @@ private void startServer() {
9392
Quarkus.asyncExit();
9493
}
9594

96-
private static void threadDump() throws IOException {
97-
// Create a timestamp with milliseconds for the file name
98-
//String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS").format(new Date());
99-
//String fileName = "/app/thread_dump_" + timestamp + ".txt";
100-
Log.info("Thread dump");
101-
String threadDumpStr = "";
102-
103-
// Create a PrintWriter to write the thread dump to a file
104-
//try (PrintWriter writer = new PrintWriter(new FileWriter(fileName))) {
105-
// Get the ThreadMXBean instance
106-
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
107-
108-
// Get all thread IDs
109-
long[] threadIds = threadMXBean.getAllThreadIds();
110-
ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadIds, Integer.MAX_VALUE);
111-
112-
// Write the thread information to the file
113-
for (ThreadInfo threadInfo : threadInfos) {
114-
threadDumpStr += "Thread ID: " + threadInfo.getThreadId() + " Name: " + threadInfo.getThreadName() + "\n";
115-
threadDumpStr += "Thread State: " + threadInfo.getThreadState() + "\n";
116-
StackTraceElement[] stackTrace = threadInfo.getStackTrace();
117-
for (StackTraceElement stackTraceElement : stackTrace) {
118-
threadDumpStr += "\t" + stackTraceElement + "\n";
119-
}
120-
}
121-
//}
122-
Log.info(threadDumpStr);
123-
}
124-
12595
@PreDestroy
12696
public void stop() {
12797
executor.shutdownNow();

0 commit comments

Comments
 (0)