@Override public void run() { while (true) { // log.debug("Status available="+availableSlots+" used="+usedSlots+" queue="+queue.size()); if (availableSlots.intValue() > usedSlots.intValue() && queue.size() > 0) { usedSlots.incrementAndGet(); AnalysisRunner currentRun = queue.removeFirst(); currentRun.addAnalysisListener(this); Thread t = new Thread(currentRun); t.start(); } try { Thread.sleep(500); } catch (InterruptedException e) { } } }