I have been trying to get to the problem of what is causing random shutdowns. I know a few servers have been getting this issue so would be nice to solve the issue.
I have found out that the shutdown hook is being fired however the server is kept running as a process...
Code:
try {
while (!Server.shutdownServer) {
if (sleepTime >= 0)
Thread.sleep(sleepTime);
else
Thread.sleep(600);
engineTimer.reset();
itemHandler.process();
playerHandler.process();
npcHandler.process();
shopHandler.process();
objectManager.process();
fightPits.process();
cycleTime = engineTimer.elapsed();
sleepTime = cycleRate - cycleTime;
totalCycleTime += cycleTime;
cycles++;
debug();
}
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("A fatal exception has been thrown!");
for (Player p : PlayerHandler.players) {
if (p == null)
continue;
PlayerSave.saveGame((Client) p);
System.out.println("Saved game for " + p.playerName + ".");
}
}
Runtime.getRuntime().addShutdownHook(new Thread());
acceptor = null;
connectionHandler = null;
sac = null;
System.exit(0);
}
Which I have my server terminal being outputted to a file(linux)... Now from what I can see and understand the shutdown hook is fired when the server is exited / killed. However with this bit of code Runtime.getRuntime().addShutdownHook(new Thread()); the server will keep running which leads me to believe it has something to do with the main server loop. Now that would only be exited if shutdownServer was turned to true which a quick search of the server and no instances of shutdownServer = true exist...
I am completely lost to what would be causing this issue. The several servers I have worked on have ample amount of resources so its not due to memory. Could someone help out with this as I am very baffled into what could be causing the server to be terminated.