Source:
<code><START> protected TaskWrapper getNextTask() throws InterruptedException { <END> while (runningThread != null) { TaskWrapper nextScheduledTask = scheduleQueue.peekFirst(); TaskWrapper nextExecuteTask = executeQueue.peek(); if (nextExecuteTask != null) { if (nextScheduledTask != null) { long scheduleDelay; long executeDelay; clockWrapper.stopForcingUpdate(); try { scheduleDelay = nextScheduledTask.getDelay(TimeUnit.MILLISECONDS); executeDelay = nextExecuteTask.getDelay(TimeUnit.MILLISECONDS); } finally { clockWrapper.resumeForcingUpdate(); } if (scheduleDelay < executeDelay) { synchronized (scheduleQueue.getModificationLock()) { if (scheduleQueue.remove(nextScheduledTask)) { nextScheduledTask.executing(); return nextScheduledTask; } } } else { synchronized (executeQueueRemoveLock) { if (executeQueue.remove(nextExecuteTask)) { nextExecuteTask.executing(); return nextExecuteTask; } } } } else { synchronized (executeQueueRemoveLock) { if (executeQueue.remove(nextExecuteTask)) { nextExecuteTask.executing(); return nextExecuteTask; } } } } else if (nextScheduledTask != null) { if (nextScheduledTask.getDelay(TimeUnit.MILLISECONDS) <= 0) { synchronized (scheduleQueue.getModificationLock()) { if (scheduleQueue.remove(nextScheduledTask)) { nextScheduledTask.executing(); return nextScheduledTask; } } } else { LockSupport.parkNanos(Clock.NANOS_IN_MILLISECOND * nextScheduledTask.getDelay(TimeUnit.MILLISECONDS)); } } else { LockSupport.park(); } if (Thread.currentThread().isInterrupted()) { throw new InterruptedException(); } } return null; }</code><technical_language>I do alot of improvement here. I dont causing head I bet get rid of a checks reduce complexity pretty good consistency queues a bit more thought put it</technical_language>

Target:
protected TaskWrapper getNextTask() throws InterruptedException { while (runningThread != null) { TaskWrapper nextScheduledTask = scheduleQueue.peekFirst(); TaskWrapper nextExecuteTask = executeQueue.peek(); if (nextExecuteTask != null) { if (nextScheduledTask != null) { long scheduleDelay; long executeDelay; clockWrapper.stopForcingUpdate(); try { scheduleDelay = nextScheduledTask.getDelay(TimeUnit.MILLISECONDS); executeDelay = nextExecuteTask.getDelay(TimeUnit.MILLISECONDS); } finally { clockWrapper.resumeForcingUpdate(); } if (scheduleDelay < executeDelay) { synchronized (scheduleQueue.getModificationLock()) { if (scheduleQueue.remove(nextScheduledTask)) { nextScheduledTask.executing(); return nextScheduledTask; } } } else { if (executeQueue.remove(nextExecuteTask)) { nextExecuteTask.executing(); return nextExecuteTask; } } } else { if (executeQueue.remove(nextExecuteTask)) { nextExecuteTask.executing(); return nextExecuteTask; } } } else if (nextScheduledTask != null) { if (nextScheduledTask.getDelay(TimeUnit.MILLISECONDS) <= 0) { synchronized (scheduleQueue.getModificationLock()) { if (scheduleQueue.remove(nextScheduledTask)) { nextScheduledTask.executing(); return nextScheduledTask; } } } else { LockSupport.parkNanos(Clock.NANOS_IN_MILLISECOND * nextScheduledTask.getDelay(TimeUnit.MILLISECONDS)); } } else { LockSupport.park(); } if (Thread.currentThread().isInterrupted()) { throw new InterruptedException(); } } return null; }