mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Fixed double thread issue! :D
This commit is contained in:
@@ -91,7 +91,6 @@ public class GameState implements Runnable {
|
|||||||
|
|
||||||
resetStartTime();
|
resetStartTime();
|
||||||
|
|
||||||
new Thread(this).start(); //Run the auto updates on the game state
|
|
||||||
new Thread(this, "GameState").start(); //Run the auto updates on the game state
|
new Thread(this, "GameState").start(); //Run the auto updates on the game state
|
||||||
|
|
||||||
marks = new MarkOrder().getAllMarks();
|
marks = new MarkOrder().getAllMarks();
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import seng302.gameServer.server.messages.Message;
|
|||||||
* Will call .clientDisconnected on the delegate when a heartbeat message
|
* Will call .clientDisconnected on the delegate when a heartbeat message
|
||||||
* cannot be sent to a player
|
* cannot be sent to a player
|
||||||
*/
|
*/
|
||||||
public class HeartbeatThread extends Thread{
|
public class HeartbeatThread implements Runnable {
|
||||||
private final int HEARTBEAT_PERIOD = 200;
|
private final int HEARTBEAT_PERIOD = 200;
|
||||||
private ClientConnectionDelegate delegate;
|
private ClientConnectionDelegate delegate;
|
||||||
private Integer seqNum;
|
private Integer seqNum;
|
||||||
@@ -23,6 +23,9 @@ public class HeartbeatThread extends Thread{
|
|||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
seqNum = 0;
|
seqNum = 0;
|
||||||
disconnectedPlayers = new Stack<>();
|
disconnectedPlayers = new Stack<>();
|
||||||
|
|
||||||
|
Thread thread = new Thread(this, "HeartBeat");
|
||||||
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -56,14 +56,9 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
|
|||||||
|
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
ServerListenThread serverListenThread;
|
|
||||||
HeartbeatThread heartbeatThread;
|
|
||||||
|
|
||||||
serverListenThread = new ServerListenThread(serverSocket, this);
|
new HeartbeatThread(this);
|
||||||
heartbeatThread = new HeartbeatThread(this);
|
new ServerListenThread(serverSocket, this);
|
||||||
|
|
||||||
heartbeatThread.start();
|
|
||||||
serverListenThread.start();
|
|
||||||
|
|
||||||
//You should handle interrupts in some way, so that the thread won't keep on forever if you exit the app.
|
//You should handle interrupts in some way, so that the thread won't keep on forever if you exit the app.
|
||||||
while (!terminated) {
|
while (!terminated) {
|
||||||
|
|||||||
@@ -8,13 +8,16 @@ import java.net.Socket;
|
|||||||
* A class for a thread to listen to connections
|
* A class for a thread to listen to connections
|
||||||
* Created by wmu16 on 11/07/17.
|
* Created by wmu16 on 11/07/17.
|
||||||
*/
|
*/
|
||||||
public class ServerListenThread extends Thread{
|
public class ServerListenThread implements Runnable {
|
||||||
private ServerSocket serverSocket;
|
private ServerSocket serverSocket;
|
||||||
private ClientConnectionDelegate delegate;
|
private ClientConnectionDelegate delegate;
|
||||||
|
|
||||||
public ServerListenThread(ServerSocket serverSocket, ClientConnectionDelegate delegate){
|
public ServerListenThread(ServerSocket serverSocket, ClientConnectionDelegate delegate){
|
||||||
this.serverSocket = serverSocket;
|
this.serverSocket = serverSocket;
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
|
|
||||||
|
Thread thread = new Thread(this, "ServerListen");
|
||||||
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user