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
181 * Schedules the specified task for execution after the specified delay.
183 * @param task task to be scheduled.
184 * @param delay delay in milliseconds before task is to be executed.
187 * @throws IllegalStateException if task was already scheduled or
189 * @throws NullPointerException if {@code task} is null
191 public void schedule(TimerTask task, long delay) {
194 sched(task, System.currentTimeMillis()+delay, 0);
198 * Schedules the specified task for execution at the specified time. If
199 * the time is in the past, the task is scheduled for immediate execution.
201 * @param task task to be scheduled.
202 * @param time time at which task is to be executed.
204 * @throws IllegalStateException if task was already scheduled or
206 * @throws NullPointerException if {@code task} or {@code time} is null
208 public void schedule(TimerTask task, Date time) {
209 sched(task, time.getTime(), 0);
213 * Schedules the specified task for repeated <i>fixed-delay execution</i>,
234 * @param task task to be scheduled.
235 * @param delay delay in milliseconds before task is to be executed.
236 * @param period time in milliseconds between successive task executions.
240 * @throws IllegalStateException if task was already scheduled or
242 * @throws NullPointerException if {@code task} is null
244 public void schedule(TimerTask task, long delay, long period) {
249 sched(task, System.currentTimeMillis()+delay, -period);
253 * Schedules the specified task for repeated <i>fixed-delay execution</i>,
276 * @param task task to be scheduled.
277 * @param firstTime First time at which task is to be executed.
278 * @param period time in milliseconds between successive task executions.
281 * @throws IllegalStateException if task was already scheduled or
283 * @throws NullPointerException if {@code task} or {@code firstTime} is null
285 public void schedule(TimerTask task, Date firstTime, long period) {
288 sched(task, firstTime.getTime(), -period);
292 * Schedules the specified task for repeated <i>fixed-rate execution</i>,
314 * @param task task to be scheduled.
315 * @param delay delay in milliseconds before task is to be executed.
316 * @param period time in milliseconds between successive task executions.
320 * @throws IllegalStateException if task was already scheduled or
322 * @throws NullPointerException if {@code task} is null
324 public void scheduleAtFixedRate(TimerTask task, long delay, long period) {
329 sched(task, System.currentTimeMillis()+delay, period);
333 * Schedules the specified task for repeated <i>fixed-rate execution</i>,
358 * @param task task to be scheduled.
359 * @param firstTime First time at which task is to be executed.
360 * @param period time in milliseconds between successive task executions.
363 * @throws IllegalStateException if task was already scheduled or
365 * @throws NullPointerException if {@code task} or {@code firstTime} is null
367 public void scheduleAtFixedRate(TimerTask task, Date firstTime,
371 sched(task, firstTime.getTime(), period);
375 * Schedule the specified timer task for execution at the specified
377 * positive, the task is scheduled for repeated execution; if period is
378 * zero, the task is scheduled for one-time execution. Time is specified
379 * in Date.getTime() format. This method checks timer state, task state,
383 * @throws IllegalStateException if task was already scheduled or
385 * @throws NullPointerException if {@code task} is null
387 private void sched(TimerTask task, long time, long period) {
400 synchronized(task.lock) {
401 if (task.state != TimerTask.VIRGIN)
404 task.nextExecutionTime = time;
405 task.period = period;
406 task.state = TimerTask.SCHEDULED;
409 queue.add(task);
410 if (queue.getMin() == task)
417 * Does not interfere with a currently executing task (if it exists).
422 * timer task that was invoked by this timer absolutely guarantees that
423 * the ongoing task execution is the last task execution that will ever
438 * Removes all cancelled tasks from this timer's task queue. <i>Calling
452 * a task scheduled on this timer.
477 * This "helper class" implements the timer's task execution thread, which
522 TimerTask task;
533 task = queue.getMin();
534 synchronized(task.lock) {
535 if (task.state == TimerTask.CANCELLED) {
540 executionTime = task.nextExecutionTime;
542 if (task.period == 0) { // Non-repeating, remove
544 task.state = TimerTask.EXECUTED;
545 } else { // Repeating task, reschedule
547 task.period<0 ? currentTime - task.period
548 : executionTime + task.period);
556 task.run();
564 * This class represents a timer task queue: a priority queue of TimerTasks,
595 * Adds a new task to the priority queue.
597 void add(TimerTask task) {
602 queue[++size] = task;
607 * Return the "head task" of the priority queue. (The head task is an
608 * task with the lowest nextExecutionTime.)
615 * Return the ith task in the priority queue, where i ranges from 1 (the
616 * head task, which is returned by getMin) to the number of tasks on the
624 * Remove the head task from the priority queue.
645 * Sets the nextExecutionTime associated with the head task to the
664 // Null out task references to prevent memory leak