forked from j62/ctbrec
1
0
Fork 0

Interrupt keep alive thread on reconnect

On reconnect interrupt the current keep alive thread, so that we don't
pile up a bunch keep alive threads, if the there is a problem with the
websocket connection.
This commit is contained in:
0xboobface 2020-07-11 14:15:34 +02:00
parent 716c75c3d2
commit 9bb18426a6
1 changed files with 6 additions and 2 deletions

View File

@ -56,6 +56,7 @@ public class MyFreeCamsClient {
private static MyFreeCamsClient instance; private static MyFreeCamsClient instance;
private MyFreeCams mfc; private MyFreeCams mfc;
private WebSocket ws; private WebSocket ws;
private Thread keepAlive;
private Moshi moshi; private Moshi moshi;
private volatile boolean running = false; private volatile boolean running = false;
@ -562,8 +563,11 @@ public class MyFreeCamsClient {
} }
private void startKeepAlive(WebSocket ws) { private void startKeepAlive(WebSocket ws) {
Thread keepAlive = new Thread(() -> { if (keepAlive != null) {
while (running) { keepAlive.interrupt();
}
keepAlive = new Thread(() -> {
while (running && !Thread.currentThread().isInterrupted()) {
try { try {
if (!connecting) { if (!connecting) {
LOG.trace("--> NULL to keep the connection alive"); LOG.trace("--> NULL to keep the connection alive");