/** * Sleeps for the cycle delay. * * @throws InterruptedException */ private void sleep() { try { long sleepTime = cycleRate - cycleTimer.elapsed(); boolean sleep = sleepTime > 0 && sleepTime <= 600; for (int i = 0; i < PacketManager.SIZE; i++) { Benchmark b = PacketManager.packetBenchmarks[i]; if (!sleep && b.getTime() > 0) System.out.println( "Packet " + i + "[" + PacketManager.packets[i].getClass().getSimpleName() + "] took " + b.getTime() + " ms."); b.reset(); } if (sleep) { Benchmarks.resetAll(); // System.out.println("[ENGINE]: Sleeping for " + sleepTime + "ms"); Thread.sleep(sleepTime); } else { // The server has reached maximum load, players may now lag. cycle = (100 + Math.abs(sleepTime) / (cycleRate / 100)); /*if (cycle > 999) { initiateRestart(); }*/ System.out.println("[WARNING]: Server load: " + cycle + "%!"); Benchmarks.printAll(); Benchmarks.resetAll(); for (int i = 0; i < 5; i++) System.out.println(""); } } catch (Exception ex) { ex.printStackTrace(); } finally { cycleTimer.reset(); } }