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:
parent
716c75c3d2
commit
9bb18426a6
|
@ -56,6 +56,7 @@ public class MyFreeCamsClient {
|
|||
private static MyFreeCamsClient instance;
|
||||
private MyFreeCams mfc;
|
||||
private WebSocket ws;
|
||||
private Thread keepAlive;
|
||||
private Moshi moshi;
|
||||
private volatile boolean running = false;
|
||||
|
||||
|
@ -562,8 +563,11 @@ public class MyFreeCamsClient {
|
|||
}
|
||||
|
||||
private void startKeepAlive(WebSocket ws) {
|
||||
Thread keepAlive = new Thread(() -> {
|
||||
while (running) {
|
||||
if (keepAlive != null) {
|
||||
keepAlive.interrupt();
|
||||
}
|
||||
keepAlive = new Thread(() -> {
|
||||
while (running && !Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
if (!connecting) {
|
||||
LOG.trace("--> NULL to keep the connection alive");
|
||||
|
|
Loading…
Reference in New Issue