Lines Matching refs:task

37  * Timer tasks should complete quickly.  If a timer task takes excessive time
38 * to complete, it "hogs" the timer's task execution thread. This can, in
40 * execute in rapid succession when (and if) the offending task finally
44 * <i>and</i> all outstanding tasks have completed execution, the timer's task
47 * default, the task execution thread does not run as a <i>daemon thread</i>,
49 * wants to terminate a timer's task execution thread rapidly, the caller
52 * <p>If the timer's task execution thread terminates unexpectedly, for
54 * attempt to schedule a task on the timer will result in an
78 * it uses a binary heap to represent its task queue, so the cost to schedule
79 * a task is O(log n), where n is the number of concurrently scheduled tasks.
91 * The timer task queue. This data structure is shared with the timer
104 * This object causes the timer's task execution thread to exit
180 * Schedules the specified task for execution after the specified delay.
182 * @param task task to be scheduled.
183 * @param delay delay in milliseconds before task is to be executed.
186 * @throws IllegalStateException if task was already scheduled or
188 * @throws NullPointerException if {@code task} is null
190 public void schedule(TimerTask task, long delay) {
193 sched(task, System.currentTimeMillis()+delay, 0);
197 * Schedules the specified task for execution at the specified time. If
198 * the time is in the past, the task is scheduled for immediate execution.
200 * @param task task to be scheduled.
201 * @param time time at which task is to be executed.
203 * @throws IllegalStateException if task was already scheduled or
205 * @throws NullPointerException if {@code task} or {@code time} is null
207 public void schedule(TimerTask task, Date time) {
208 sched(task, time.getTime(), 0);
212 * Schedules the specified task for repeated <i>fixed-delay execution</i>,
233 * @param task task to be scheduled.
234 * @param delay delay in milliseconds before task is to be executed.
235 * @param period time in milliseconds between successive task executions.
239 * @throws IllegalStateException if task was already scheduled or
241 * @throws NullPointerException if {@code task} is null
243 public void schedule(TimerTask task, long delay, long period) {
248 sched(task, System.currentTimeMillis()+delay, -period);
252 * Schedules the specified task for repeated <i>fixed-delay execution</i>,
275 * @param task task to be scheduled.
276 * @param firstTime First time at which task is to be executed.
277 * @param period time in milliseconds between successive task executions.
280 * @throws IllegalStateException if task was already scheduled or
282 * @throws NullPointerException if {@code task} or {@code firstTime} is null
284 public void schedule(TimerTask task, Date firstTime, long period) {
287 sched(task, firstTime.getTime(), -period);
291 * Schedules the specified task for repeated <i>fixed-rate execution</i>,
313 * @param task task to be scheduled.
314 * @param delay delay in milliseconds before task is to be executed.
315 * @param period time in milliseconds between successive task executions.
319 * @throws IllegalStateException if task was already scheduled or
321 * @throws NullPointerException if {@code task} is null
323 public void scheduleAtFixedRate(TimerTask task, long delay, long period) {
328 sched(task, System.currentTimeMillis()+delay, period);
332 * Schedules the specified task for repeated <i>fixed-rate execution</i>,
357 * @param task task to be scheduled.
358 * @param firstTime First time at which task is to be executed.
359 * @param period time in milliseconds between successive task executions.
362 * @throws IllegalStateException if task was already scheduled or
364 * @throws NullPointerException if {@code task} or {@code firstTime} is null
366 public void scheduleAtFixedRate(TimerTask task, Date firstTime,
370 sched(task, firstTime.getTime(), period);
374 * Schedule the specified timer task for execution at the specified
376 * positive, the task is scheduled for repeated execution; if period is
377 * zero, the task is scheduled for one-time execution. Time is specified
378 * in Date.getTime() format. This method checks timer state, task state,
382 * @throws IllegalStateException if task was already scheduled or
384 * @throws NullPointerException if {@code task} is null
386 private void sched(TimerTask task, long time, long period) {
399 synchronized(task.lock) {
400 if (task.state != TimerTask.VIRGIN)
403 task.nextExecutionTime = time;
404 task.period = period;
405 task.state = TimerTask.SCHEDULED;
408 queue.add(task);
409 if (queue.getMin() == task)
416 * Does not interfere with a currently executing task (if it exists).
421 * timer task that was invoked by this timer absolutely guarantees that
422 * the ongoing task execution is the last task execution that will ever
437 * Removes all cancelled tasks from this timer's task queue. <i>Calling
451 * a task scheduled on this timer.
476 * This "helper class" implements the timer's task execution thread, which
521 TimerTask task;
532 task = queue.getMin();
533 synchronized(task.lock) {
534 if (task.state == TimerTask.CANCELLED) {
539 executionTime = task.nextExecutionTime;
541 if (task.period == 0) { // Non-repeating, remove
543 task.state = TimerTask.EXECUTED;
544 } else { // Repeating task, reschedule
546 task.period<0 ? currentTime - task.period
547 : executionTime + task.period);
555 task.run();
563 * This class represents a timer task queue: a priority queue of TimerTasks,
594 * Adds a new task to the priority queue.
596 void add(TimerTask task) {
601 queue[++size] = task;
606 * Return the "head task" of the priority queue. (The head task is an
607 * task with the lowest nextExecutionTime.)
614 * Return the ith task in the priority queue, where i ranges from 1 (the
615 * head task, which is returned by getMin) to the number of tasks on the
623 * Remove the head task from the priority queue.
644 * Sets the nextExecutionTime associated with the head task to the
663 // Null out task references to prevent memory leak