You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by am...@apache.org on 2025/06/30 21:57:41 UTC
(aries-rsa) 03/03: Improve TcpServer thread names
This is an automated email from the ASF dual-hosted git repository.
amichai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-rsa.git
commit fb82303c60b8d80a6cb23d67584b868601bda3ba
Author: Amichai Rothman <am...@apache.org>
AuthorDate: Mon Jun 30 15:16:01 2025 +0300
Improve TcpServer thread names
---
.../main/java/org/apache/aries/rsa/provider/tcp/TcpServer.java | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TcpServer.java b/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TcpServer.java
index 3142f606..b30fb9d9 100644
--- a/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TcpServer.java
+++ b/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TcpServer.java
@@ -29,6 +29,7 @@ import java.net.Socket;
import java.net.SocketException;
import java.util.Map;
import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
import org.apache.aries.rsa.provider.tcp.ser.BasicObjectOutputStream;
import org.apache.aries.rsa.provider.tcp.ser.BasicObjectInputStream;
@@ -50,10 +51,13 @@ public class TcpServer implements Closeable, Runnable {
private ThreadPoolExecutor executor;
public TcpServer(String bindAddress, int port, int numThreads) {
+ String addressStr;
try {
InetSocketAddress address = bindAddress == null || bindAddress.isEmpty()
? new InetSocketAddress(port)
: new InetSocketAddress(bindAddress, port);
+ addressStr = (address.getAddress() == null ? address.getHostName() : address.getAddress().getHostAddress())
+ + ":" + address.getPort();
this.serverSocket = new ServerSocket();
this.serverSocket.setReuseAddress(true);
this.serverSocket.bind(address);
@@ -62,8 +66,10 @@ public class TcpServer implements Closeable, Runnable {
}
this.running = true;
numThreads++; // plus one for server socket accepting thread
+ AtomicInteger counter = new AtomicInteger();
this.executor = new ThreadPoolExecutor(numThreads, numThreads,
- 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
+ 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),
+ r -> new Thread(r, getClass().getSimpleName() + " [" + addressStr + "]-" + counter.incrementAndGet()));
this.executor.execute(this); // server socket thread
}