forked from j62/ctbrec
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 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");
|
||||||
|
|
Loading…
Reference in New Issue