13
0

Merge pull request 'Proper waiting for subserver cleanup' (#17) from properWait into master

Reviewed-on: #17
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2021-09-17 07:45:42 +02:00
Commit ae1ca904bd

Datei anzeigen

@ -72,6 +72,7 @@ public class Subserver implements Runnable {
private final PrintWriter writer; private final PrintWriter writer;
private final ServerInfo server; private final ServerInfo server;
private final Servertype type; private final Servertype type;
private final Thread thread;
private boolean started; private boolean started;
private final List<ProxiedPlayer> cachedPlayers = new LinkedList<>(); private final List<ProxiedPlayer> cachedPlayers = new LinkedList<>();
@ -102,7 +103,8 @@ public class Subserver implements Runnable {
serverName, address, "SteamWar.de - Subserver", false); serverName, address, "SteamWar.de - Subserver", false);
this.writer = new PrintWriter(process.getOutputStream(), true); this.writer = new PrintWriter(process.getOutputStream(), true);
ProxyServer.getInstance().getScheduler().runAsync(Persistent.getInstance(), this); this.thread = new Thread(this, "Subserver " + serverName);
this.thread.start();
} }
public ServerInfo getServer(){ public ServerInfo getServer(){
@ -133,6 +135,7 @@ public class Subserver implements Runnable {
try { try {
if(!process.waitFor(1, TimeUnit.MINUTES)) if(!process.waitFor(1, TimeUnit.MINUTES))
process.destroy(); process.destroy();
thread.join();
}catch(InterruptedException e){ }catch(InterruptedException e){
logger.log(Level.SEVERE, "Subserver stop interrupted!", e); logger.log(Level.SEVERE, "Subserver stop interrupted!", e);
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
@ -144,6 +147,7 @@ public class Subserver implements Runnable {
if(!process.waitFor(5, TimeUnit.MINUTES) && server.getPlayers().isEmpty()){ if(!process.waitFor(5, TimeUnit.MINUTES) && server.getPlayers().isEmpty()){
process.destroy(); process.destroy();
} }
thread.join();
}catch(InterruptedException e){ }catch(InterruptedException e){
logger.log(Level.SEVERE, "Subserver stop interrupted!", e); logger.log(Level.SEVERE, "Subserver stop interrupted!", e);
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();