Skip to content

Commit a8a3579

Browse files
committed
Terminate ping thread when save&restore app is closed
1 parent 344a943 commit a8a3579

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

core/websocket/src/main/java/org/phoebus/core/websocket/WebSocketClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class WebSocketClient implements WebSocket.Listener {
3535
private final Consumer<CharSequence> onTextCallback;
3636

3737
private final AtomicBoolean attemptReconnect = new AtomicBoolean();
38+
private final AtomicBoolean keepPinging = new AtomicBoolean();
3839
private CountDownLatch pingCountdownLatch;
3940

4041
/**
@@ -90,6 +91,7 @@ public void onOpen(WebSocket webSocket) {
9091
connectCallback.run();
9192
}
9293
logger.log(Level.INFO, "Connected to " + uri);
94+
keepPinging.set(true);
9395
new Thread(new PingRunnable()).start();
9496
}
9597

@@ -134,7 +136,7 @@ public CompletionStage<?> onClose(WebSocket webSocket,
134136
* is called.
135137
*/
136138
public void sendPing() {
137-
logger.log(Level.FINE, "Sending ping");
139+
logger.log(Level.FINE, Thread.currentThread().getName() + " Sending ping");
138140
webSocket.sendPing(ByteBuffer.allocate(0));
139141
}
140142

@@ -175,6 +177,7 @@ public CompletionStage<?> onText(WebSocket webSocket,
175177
* @param reason Custom reason text.
176178
*/
177179
public void close(String reason) {
180+
keepPinging.set(false);
178181
webSocket.sendClose(1000, reason);
179182
}
180183

@@ -197,7 +200,7 @@ private class PingRunnable implements Runnable {
197200

198201
@Override
199202
public void run() {
200-
while (true) {
203+
while (keepPinging.get()) {
201204
pingCountdownLatch = new CountDownLatch(1);
202205
sendPing();
203206
try {

0 commit comments

Comments
 (0)