The following code:
long msBefore = System.currentTimeMillis(); //Thread.currentThread().setPriority(Thread.MAX_PRIORITY); try {Thread.sleep(200); } catch (I
You're not taking into account the time it spends processing.
try { long processingStart = System.currentTimeMillis(); long processingFinish = System.currentTimeMillis(); long processTime = 600 - (processingFinish - processingStart); Thread.sleep(processTime); } catch (InterruptedException ex) { }