Skip to content

Commit 5cac132

Browse files
committed
Added protected methods to customize client thread names.
closes TooTallNate#1421
1 parent cd08f83 commit 5cac132

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/main/java/org/java_websocket/AbstractWebSocket.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ protected void startConnectionLostTimer() {
201201
private void restartConnectionLostTimer() {
202202
cancelConnectionLostTimer();
203203
connectionLostCheckerService = Executors
204-
.newSingleThreadScheduledExecutor(new NamedThreadFactory("connectionLostChecker", daemon));
204+
.newSingleThreadScheduledExecutor(new NamedThreadFactory(connectionLostThreadPrefix(), daemon));
205205
Runnable connectionLostChecker = new Runnable() {
206206

207207
/**
@@ -233,6 +233,10 @@ public void run() {
233233
TimeUnit.NANOSECONDS);
234234
}
235235

236+
protected String connectionLostThreadPrefix () {
237+
return "connectionLostChecker";
238+
}
239+
236240
/**
237241
* Send a ping to the endpoint or close the connection since the other endpoint did not respond
238242
* with a ping

src/main/java/org/java_websocket/client/WebSocketClient.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,18 @@ public void connect() {
380380
}
381381
connectReadThread = new Thread(this);
382382
connectReadThread.setDaemon(isDaemon());
383-
connectReadThread.setName("WebSocketConnectReadThread-" + connectReadThread.getId());
383+
connectReadThread.setName(connectReadThreadName(connectReadThread.getId()));
384384
connectReadThread.start();
385385
}
386386

387+
protected String connectReadThreadName (long threadId) {
388+
return "WebSocketConnectReadThread-" + threadId;
389+
}
390+
391+
protected String writeThreadName (long threadId) {
392+
return "WebSocketWriteThread-" + threadId;
393+
}
394+
387395
/**
388396
* Same as <code>connect</code> but blocks until the websocket connected or failed to do so.<br>
389397
*
@@ -819,7 +827,7 @@ private class WebsocketWriteThread implements Runnable {
819827

820828
@Override
821829
public void run() {
822-
Thread.currentThread().setName("WebSocketWriteThread-" + Thread.currentThread().getId());
830+
Thread.currentThread().setName(writeThreadName(Thread.currentThread().getId()));
823831
try {
824832
runWriteData();
825833
} catch (IOException e) {

0 commit comments

Comments
 (0)