mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 08:49:40 -05:00
Add static to fields for single instance to manage all heartbeat threads. Far more efficient than 1 thread each sleeping!
This commit is contained in:
@@ -30,13 +30,13 @@ import java.util.concurrent.*;
|
|||||||
public class WebSocketHeartbeatTask
|
public class WebSocketHeartbeatTask
|
||||||
{
|
{
|
||||||
// Single shared pool for all heartbeat tasks
|
// Single shared pool for all heartbeat tasks
|
||||||
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, r -> {
|
private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, r -> {
|
||||||
Thread t = new Thread(r, "heartbeat-pool");
|
Thread t = new Thread(r, "heartbeat-pool");
|
||||||
t.setDaemon(true);
|
t.setDaemon(true);
|
||||||
return t;
|
return t;
|
||||||
});
|
});
|
||||||
private final Map<WebSocket, ScheduledFuture<?>> tasks = new ConcurrentHashMap<>();
|
private static final Map<WebSocket, ScheduledFuture<?>> tasks = new ConcurrentHashMap<>();
|
||||||
private final Map<WebSocket, Long> commTime = new ConcurrentHashMap<>();
|
private static final Map<WebSocket, Long> commTime = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private final byte[] heartbeatBytes = Base64.getDecoder().decode("MgJwYjoCaGI="); // Used to be '3A026862' aka ':\x02hb', now is '2\x02pb:\x02hb'.
|
private final byte[] heartbeatBytes = Base64.getDecoder().decode("MgJwYjoCaGI="); // Used to be '3A026862' aka ':\x02hb', now is '2\x02pb:\x02hb'.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user