Try this:
Code:
public class Process extends Thread {
public static int cycleTime = 500;
@Override
public void run() {
int waitFails = 0;
long lastTicks = System.currentTimeMillis();
long totalTimeSpentProcessing = 0;
int cycle = 0;
while (!Server.shutdownServer) {
try {
if (Server.updateServer)
Server.calcTime();
Server.playerHandler.process();
Server.npcHandler.process();
Server.itemHandler.process();
Server.shopHandler.process();
long timeSpent = System.currentTimeMillis() - lastTicks;
totalTimeSpentProcessing += timeSpent;
if (timeSpent >= cycleTime) {
timeSpent = cycleTime;
}
try {
Thread.sleep(cycleTime - timeSpent);
} catch (java.lang.Exception _ex) {
}
lastTicks = System.currentTimeMillis();
cycle++;
if (cycle % 100 == 0) {
float time = ((float) totalTimeSpentProcessing) / cycle;
}
if (Server.ShutDown == true) {
if (Server.ShutDownCounter >= 100) {
Server.shutdownServer = true;
}
Server.ShutDownCounter++;
}
} catch (Exception e) {
e.printStackTrace();
}
}
// shut down the server
EventManager.getSingleton().shutdown();
Server.playerHandler.destruct();
Server.clientHandler.killServer();
Server.clientHandler = null;
}
}
I take NO CREDIT for this.