You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/org/java_websocket/client/WebSocketClient.java
+20-8Lines changed: 20 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -93,6 +93,11 @@ public abstract class WebSocketClient extends AbstractWebSocket implements Runna
93
93
*/
94
94
privateThreadwriteThread;
95
95
96
+
/**
97
+
* The thread to connect and read message
98
+
*/
99
+
privateThreadconnectReadThread;
100
+
96
101
/**
97
102
* The draft to use
98
103
*/
@@ -239,12 +244,20 @@ public boolean reconnectBlocking() throws InterruptedException {
239
244
* @since 1.3.8
240
245
*/
241
246
privatevoidreset() {
247
+
Threadcurrent = Thread.currentThread();
248
+
if (current == writeThread || current == connectReadThread) {
249
+
thrownewIllegalStateException("You cannot initialize a reconnect out of the websocket thread. Use reconnect in another thread to insure a successful cleanup.");
250
+
}
242
251
try {
243
252
closeBlocking();
244
253
if( writeThread != null ) {
245
254
this.writeThread.interrupt();
246
255
this.writeThread = null;
247
256
}
257
+
if( connectReadThread != null ) {
258
+
this.connectReadThread.interrupt();
259
+
this.connectReadThread = null;
260
+
}
248
261
this.draft.reset();
249
262
if( this.socket != null ) {
250
263
this.socket.close();
@@ -264,11 +277,11 @@ private void reset() {
264
277
* Initiates the websocket connection. This method does not block.
265
278
*/
266
279
publicvoidconnect() {
267
-
if( writeThread != null )
280
+
if( connectReadThread != null )
268
281
thrownewIllegalStateException( "WebSocketClient objects are not reuseable" );
0 commit comments