Skip to content

Commit e41589a

Browse files
committed
Try dumping threads differently.
1 parent 405a039 commit e41589a

File tree

4 files changed

+15
-37
lines changed

4 files changed

+15
-37
lines changed

deploy/tasks/buildah-oci-ta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ spec:
518518
519519
# With expansion
520520
cat >> /app/build-script.sh << EOF
521-
for ((i=1; i<=30; i++)); do
521+
for ((i=1; i<=17; i++)); do
522522
echo "request #$i"
523523
curl --max-time 30 -v -x http://localhost:8080 "http://${CACHE_HOST}/v2/cache/rebuild-central/1658389751000/org/sonatype/oss/oss-parent/7/oss-parent-7.pom"
524524
sleep 0.1

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class DomainProxyClient {
5252
public void start() {
5353
Log.info("Starting domain proxy client...");
5454
Log.infof("Byte buffer size %d", byteBufferSize); // TODO Remove
55-
executor = Executors.newCachedThreadPool();
55+
executor = Executors.newVirtualThreadPerTaskExecutor();
5656
executor.submit(this::startClient);
5757
}
5858

@@ -77,9 +77,7 @@ private void startClient() {
7777
.open(UnixDomainSocketAddress.of(domainSocket));
7878
executor.submit(channelToChannelBiDirectionalHandler(byteBufferSize, httpClientChannel,
7979
domainSocketChannel));
80-
Log.info("Before thread dump");
8180
CommonIOUtil.threadDump();
82-
Log.info("After thread dump");
8381
}
8482
}
8583
}

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

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
import static java.lang.Thread.currentThread;
44

55
import java.io.IOException;
6-
import java.lang.management.ManagementFactory;
7-
import java.lang.management.ThreadInfo;
8-
import java.lang.management.ThreadMXBean;
96
import java.nio.ByteBuffer;
107
import java.nio.channels.SelectionKey;
118
import java.nio.channels.Selector;
129
import java.nio.channels.SocketChannel;
1310
import java.util.Iterator;
11+
import java.util.Map;
1412

1513
import org.jboss.logging.Logger;
1614

@@ -164,36 +162,20 @@ private static String getChannelName(final SocketChannel channel) {
164162
return channelName;
165163
}
166164

167-
public static void threadDump() throws IOException {
168-
// Create a timestamp with milliseconds for the file name
169-
//String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS").format(new Date());
170-
//String fileName = "/app/thread_dump_" + timestamp + ".txt";
171-
LOG.info("Thread dump");
165+
public static void threadDump() {
166+
LOG.info("Before thread dump");
172167
String threadDumpStr = "";
173-
174-
// Create a PrintWriter to write the thread dump to a file
175-
//try (PrintWriter writer = new PrintWriter(new FileWriter(fileName))) {
176-
// Get the ThreadMXBean instance
177-
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
178-
179-
// Get all thread IDs
180-
long[] threadIds = threadMXBean.getAllThreadIds();
181-
ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadIds, Integer.MAX_VALUE);
182-
183-
// Write the thread information to the file
184-
for (ThreadInfo threadInfo : threadInfos) {
185-
LOG.info("Thread ID: " + threadInfo.getThreadId() + " Name: " + threadInfo.getThreadName());
186-
LOG.info("Thread State: " + threadInfo.getThreadState());
187-
threadDumpStr += "Thread ID: " + threadInfo.getThreadId() + " Name: " + threadInfo.getThreadName() + "\n";
188-
threadDumpStr += "Thread State: " + threadInfo.getThreadState() + "\n";
189-
StackTraceElement[] stackTrace = threadInfo.getStackTrace();
190-
for (StackTraceElement stackTraceElement : stackTrace) {
191-
LOG.info("\t" + stackTraceElement);
192-
threadDumpStr += "\t" + stackTraceElement + "\n";
168+
Map<Thread, StackTraceElement[]> threadMap = Thread.getAllStackTraces();
169+
for (Map.Entry<Thread, StackTraceElement[]> entry : threadMap.entrySet()) {
170+
Thread thread = entry.getKey();
171+
StackTraceElement[] stackTrace = entry.getValue();
172+
threadDumpStr += "Thread: " + thread.getName() + " [ID: " + thread.getId() + "]\n";
173+
threadDumpStr += "Thread Type: " + (thread.isVirtual() ? "Virtual" : "Platform") + "\n";
174+
for (StackTraceElement ste : stackTrace) {
175+
threadDumpStr += "\t" + ste + "\n";
193176
}
194177
}
195-
//}
196-
197178
LOG.info(threadDumpStr);
179+
LOG.info("After thread dump");
198180
}
199181
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class DomainProxyServer {
5353
@PostConstruct
5454
public void start() {
5555
Log.infof("Byte buffer size %d", byteBufferSize); // TODO Remove
56-
executor = Executors.newCachedThreadPool();
56+
executor = Executors.newVirtualThreadPerTaskExecutor();
5757
executor.submit(this::startServer);
5858
}
5959

@@ -77,9 +77,7 @@ private void startServer() {
7777
.open(new InetSocketAddress(LOCALHOST, httpServerPort));
7878
executor.submit(channelToChannelBiDirectionalHandler(byteBufferSize, httpServerChannel,
7979
domainSocketChannel));
80-
Log.info("Before thread dump");
8180
CommonIOUtil.threadDump();
82-
Log.info("After thread dump");
8381
}
8482
}
8583
}

0 commit comments

Comments
 (0)