Lines Matching defs:queue

78  * it uses a binary heap to represent its task queue, so the cost to schedule
91 * The timer task queue. This data structure is shared with the timer
94 * and removing them from the queue when they're obsolete.
96 private final TaskQueue queue = new TaskQueue();
101 private final TimerThread thread = new TimerThread(queue);
106 * tasks in the timer queue. It is used in preference to a finalizer on
112 synchronized(queue) {
114 queue.notify(); // In case queue is empty.
395 synchronized(queue) {
408 queue.add(task);
409 if (queue.getMin() == task)
410 queue.notify();
429 synchronized(queue) {
431 queue.clear();
432 queue.notify(); // In case queue was already empty.
437 * Removes all cancelled tasks from this timer's task queue. <i>Calling
439 * eliminates the references to the cancelled tasks from the queue.
447 * is the number of tasks in the queue and c is the number of cancelled
453 * @return the number of tasks removed from the queue.
459 synchronized(queue) {
460 for (int i = queue.size(); i > 0; i--) {
461 if (queue.get(i).state == TimerTask.CANCELLED) {
462 queue.quickRemove(i);
468 queue.heapify();
477 * waits for tasks on the timer queue, executions them when they fire,
479 * non-repeating tasks from the queue.
485 * is true and there are no more tasks in our queue, there is no
487 * this field is protected by queue's monitor!
492 * Our Timer's queue. We store this reference in preference to
497 private TaskQueue queue;
499 TimerThread(TaskQueue queue) {
500 this.queue = queue;
508 synchronized(queue) {
510 queue.clear(); // Eliminate obsolete references
523 synchronized(queue) {
524 // Wait for queue to become non-empty
525 while (queue.isEmpty() && newTasksMayBeScheduled)
526 queue.wait();
527 if (queue.isEmpty())
532 task = queue.getMin();
535 queue.removeMin();
536 continue; // No action required, poll queue again
542 queue.removeMin();
545 queue.rescheduleMin(
552 queue.wait(executionTime - currentTime);
563 * This class represents a timer task queue: a priority queue of TimerTasks,
571 * Priority queue represented as a balanced binary heap: the two children
572 * of queue[n] are queue[2*n] and queue[2*n+1]. The priority queue is
574 * nextExecutionTime is in queue[1] (assuming the queue is nonempty). For
578 private TimerTask[] queue = new TimerTask[128];
581 * The number of tasks in the priority queue. (The tasks are stored in
582 * queue[1] up to queue[size]).
587 * Returns the number of tasks currently on the queue.
594 * Adds a new task to the priority queue.
598 if (size + 1 == queue.length)
599 queue = Arrays.copyOf(queue, 2*queue.length);
601 queue[++size] = task;
606 * Return the "head task" of the priority queue. (The head task is an
610 return queue[1];
614 * Return the ith task in the priority queue, where i ranges from 1 (the
616 * queue, inclusive.
619 return queue[i];
623 * Remove the head task from the priority queue.
626 queue[1] = queue[size];
627 queue[size--] = null; // Drop extra reference to prevent memory leak
632 * Removes the ith element from queue without regard for maintaining
633 * the heap invariant. Recall that queue is one-based, so
639 queue[i] = queue[size];
640 queue[size--] = null; // Drop extra ref to prevent memory leak
645 * specified value, and adjusts priority queue accordingly.
648 queue[1].nextExecutionTime = newTime;
653 * Returns true if the priority queue contains no elements.
660 * Removes all elements from the priority queue.
665 queue[i] = null;
675 * This method functions by "promoting" queue[k] up the hierarchy
676 * (by swapping it with its parent) repeatedly until queue[k]'s
682 if (queue[j].nextExecutionTime <= queue[k].nextExecutionTime)
684 TimerTask tmp = queue[j]; queue[j] = queue[k]; queue[k] = tmp;
695 * This method functions by "demoting" queue[k] down the hierarchy
696 * (by swapping it with its smaller child) repeatedly until queue[k]'s
703 queue[j].nextExecutionTime > queue[j+1].nextExecutionTime)
705 if (queue[k].nextExecutionTime <= queue[j].nextExecutionTime)
707 TimerTask tmp = queue[j]; queue[j] = queue[k]; queue[k] = tmp;