Skip to content

Commit 065e93e

Browse files
author
Noah Andrews
committed
Pass Issue666Test
1 parent f00ebef commit 065e93e

3 files changed

Lines changed: 51 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package org.java_websocket;
2727

2828
import org.java_websocket.framing.CloseFrame;
29+
import org.java_websocket.util.NamedThreadFactory;
2930
import org.slf4j.Logger;
3031
import org.slf4j.LoggerFactory;
3132

@@ -170,7 +171,7 @@ protected void startConnectionLostTimer() {
170171
*/
171172
private void restartConnectionLostTimer() {
172173
cancelConnectionLostTimer();
173-
connectionLostCheckerService = Executors.newSingleThreadScheduledExecutor();
174+
connectionLostCheckerService = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("connectionLostChecker"));
174175
Runnable connectionLostChecker = new Runnable() {
175176

176177
/**
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2019 Noah Andrews
3+
*
4+
* Permission is hereby granted, free of charge, to any person
5+
* obtaining a copy of this software and associated documentation
6+
* files (the "Software"), to deal in the Software without
7+
* restriction, including without limitation the rights to use,
8+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the
10+
* Software is furnished to do so, subject to the following
11+
* conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be
14+
* included in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
* OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
package org.java_websocket.util;
27+
28+
import java.util.concurrent.Executors;
29+
import java.util.concurrent.ThreadFactory;
30+
import java.util.concurrent.atomic.AtomicInteger;
31+
32+
public class NamedThreadFactory implements ThreadFactory {
33+
private final ThreadFactory defaultThreadFactory = Executors.defaultThreadFactory();
34+
private final AtomicInteger threadNumber = new AtomicInteger(1);
35+
private final String threadPrefix;
36+
37+
public NamedThreadFactory(String threadPrefix) {
38+
this.threadPrefix = threadPrefix;
39+
}
40+
41+
@Override
42+
public Thread newThread(Runnable runnable) {
43+
Thread thread = defaultThreadFactory.newThread(runnable);
44+
thread.setName(threadPrefix + "-" + threadNumber);
45+
return thread;
46+
}
47+
}

src/test/java/org/java_websocket/issues/Issue666Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void onStart() {
8080
}
8181
for( Thread thread : mapAfter.values() ) {
8282
String name = thread.getName();
83-
if( !name.startsWith( "WebSocketSelector-" ) && !name.startsWith( "WebSocketWorker-" ) && !name.equals( "WebSocketTimer" ) ) {
83+
if( !name.startsWith( "WebSocketSelector-" ) && !name.startsWith( "WebSocketWorker-" ) && !name.startsWith( "connectionLostChecker-" ) ) {
8484
Assert.fail( "Thread not correctly named! Is: " + name );
8585
}
8686
}
@@ -145,7 +145,7 @@ public void onStart() {
145145
}
146146
for( Thread thread : mapAfter.values() ) {
147147
String name = thread.getName();
148-
if( !name.equals( "WebSocketTimer" ) && !name.startsWith( "WebSocketWriteThread-" ) && !name.startsWith( "WebSocketConnectReadThread-" )) {
148+
if( !name.startsWith( "connectionLostChecker-" ) && !name.startsWith( "WebSocketWriteThread-" ) && !name.startsWith( "WebSocketConnectReadThread-" )) {
149149
Assert.fail( "Thread not correctly named! Is: " + name );
150150
}
151151
}

0 commit comments

Comments
 (0)