Skip to content

Commit

Permalink
Giving threads names for easier troubleshooting (#135)
Browse files Browse the repository at this point in the history
We ran into an issue were we had hundreds of Trilead threads simply using the default names Thread-1....Thread-250

With this change it would be very easy to identify to what library and connection a thread belongs to.
  • Loading branch information
Elisedlund-ericsson authored Mar 10, 2023
1 parent 287981e commit c65d8d1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/com/trilead/ssh2/transport/TransportManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ class HandlerEntry

private final Vector asynchronousQueue = new Vector();
private Thread asynchronousThread = null;


/* For auto numbering threads. */
private static long threadInitNumber;
private synchronized String nextThreadName(String prefix) {
return "Trilead_TransportManager_" + prefix + "_" + hostname +":" + port + "_" + threadInitNumber++;
}

class AsynchronousWorker extends Thread
{
public void run()
Expand Down Expand Up @@ -542,6 +548,7 @@ public void run()
});

receiveThread.setDaemon(true);
receiveThread.setName(nextThreadName("receiveThread"));
receiveThread.start();
}

Expand Down Expand Up @@ -646,6 +653,7 @@ public void sendAsynchronousMessage(byte[] msg) throws IOException
{
asynchronousThread = new AsynchronousWorker();
asynchronousThread.setDaemon(true);
asynchronousThread.setName(nextThreadName("sendThread"));
asynchronousThread.start();

/* The thread will stop after 2 seconds of inactivity (i.e., empty queue) */
Expand Down

0 comments on commit c65d8d1

Please sign in to comment.