Archived
0

оптимизировали keepAlive

This commit is contained in:
2019-01-27 19:15:25 +03:00
parent 0a833fb715
commit d4556757b4
2 changed files with 5 additions and 5 deletions

View File

@@ -6,11 +6,8 @@ import mc.core.player.PlayerManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Random;
@Component
public class KeepAliveThread extends Thread {
private static final Random RAND = new Random();
private final Object lock = new Object();
@Autowired
private PlayerManager playerManager;
@@ -25,6 +22,8 @@ public class KeepAliveThread extends Thread {
@Override
public void run() {
final KeepAlivePacket keepAlivePacket = new KeepAlivePacket();
while (!Thread.currentThread().isInterrupted()) {
while(playerManager.getCountPlayers() == 0) {
synchronized (lock) {
@@ -36,7 +35,8 @@ public class KeepAliveThread extends Thread {
}
}
playerManager.getBroadcastChannel().writeAndFlush(new KeepAlivePacket(RAND.nextLong()));
keepAlivePacket.setPayload(System.currentTimeMillis());
playerManager.getBroadcastChannel().writeAndFlush(keepAlivePacket);
try {
Thread.sleep(interval);

View File

@@ -58,7 +58,7 @@ public class WrapperNetChannel implements NetChannel {
@Override
public void writeAndFlush(SCPacket pkt) {
channel.writeAndFlush(pkt);
channel.writeAndFlush(pkt, channel.voidPromise());
}
@Override