diff --git a/src/main/java/org/java_websocket/WebSocketImpl.java b/src/main/java/org/java_websocket/WebSocketImpl.java index c2cd223b9..8fd32f673 100644 --- a/src/main/java/org/java_websocket/WebSocketImpl.java +++ b/src/main/java/org/java_websocket/WebSocketImpl.java @@ -78,6 +78,7 @@ public class WebSocketImpl implements WebSocket { */ public static final int DEFAULT_PORT = 80; + private static volatile int executionCounter = 0; /** * The default wss port of WebSockets, as defined in the spec. If the nullary constructor is used, * DEFAULT_WSS_PORT will be the port the WebSocketServer is binded to. Note that ports under 1024 @@ -569,6 +570,11 @@ public synchronized void closeConnection(int code, String message, boolean remot } handshakerequest = null; readyState = ReadyState.CLOSED; + executionCounter += 1; + } + + public static int getExecutionCounter() { + return executionCounter; } protected void closeConnection(int code, boolean remote) { diff --git a/src/test/java/org/java_websocket/issues/Issue677Test.java b/src/test/java/org/java_websocket/issues/Issue677Test.java index 52dfc94b7..0a567076d 100644 --- a/src/test/java/org/java_websocket/issues/Issue677Test.java +++ b/src/test/java/org/java_websocket/issues/Issue677Test.java @@ -116,6 +116,9 @@ public void onStart() { assertTrue("webSocket.isOpen()", webSocket0.isOpen()); webSocket0.close(); countDownLatch0.await(); + while (org.java_websocket.WebSocketImpl.getExecutionCounter() < 2) { + Thread.yield(); + } assertTrue("webSocket.isClosed()", webSocket0.isClosed()); webSocket1.connectBlocking(); assertTrue("webSocket.isOpen()", webSocket1.isOpen());