/** * Creates a new timer queue with the specified thread name * @param threadName */ public TimerQueue(String threadName) { super(threadName); m_heap = new Heap(); }
/** * Creates a new Heap whose elements are compared using the given * {@link Comparator}. * @param comparator */ public Heap(Comparator comparator) { m_comparator = comparator; clear(); }
protected Executable getJobImpl() throws InterruptedException { while (m_heap.peek() == null) { wait(); } TimerTask task = (TimerTask)m_heap.extract(); switch (task.getState()) { case TimerTask.CANCELLED: case TimerTask.EXECUTED: //don't hold onto last dead task if we wait. task = null; return getJobImpl(); case TimerTask.NEW: case TimerTask.SCHEDULED: return task; default: throw new IllegalStateException("TimerTask has an illegal state"); } } protected Runnable createQueueLoop()
protected void putJobImpl(Executable task) { m_heap.insert(task); ((TimerTask)task).setState(TimerTask.SCHEDULED); notifyAll(); } protected Executable getJobImpl() throws InterruptedException
protected void clear() { super.clear(); synchronized (this) { m_heap.clear(); } }