java.util.TimerTask翻译

来源:互联网 发布:淘宝上领的红包怎么用 编辑:程序博客网 时间:2024/06/14 00:32
 Overview Package  Class Use Tree Deprecated Index Help JavaTM 2 Platform
Std. Ed. v1.4.2
 PREV CLASS   NEXT CLASSFRAMES    NO FRAMES     All Classes SUMMARY: NESTED | FIELD | CONSTR | METHODDETAIL: FIELD | CONSTR | METHOD

java.util
Class TimerTask

java.lang.Object  extended byjava.util.TimerTask
All Implemented Interfaces:
Runnable

public abstract class TimerTask
extends Object
implements Runnable

A task that can be scheduled for one-time or repeated execution by a Timer. 由Timer安排执行一次或重复执行的任务。

Since:
1.3
See Also:
Timer

Constructor Summaryprotected TimerTask()
          Creates a new timer task. 创建一个新的计时任务。
  Method Summary booleancancel()
          Cancels this timer task. 取消该计时任务。
abstract  voidrun()
          The action to be performed by this timer task. 由计时任务执行的动作。
 longscheduledExecutionTime()
          Returns the scheduled execution time of the most recent actual execution of this task. 返回该任务安排的最近实际执行的执行时间。
  Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 

Constructor Detail

TimerTask

protected TimerTask()
Creates a new timer task. 创建一个新的计时任务。

Method Detail

run

public abstract void run()
The action to be performed by this timer task. 由计时任务执行的动作。

Specified by:
run in interface Runnable
See Also:
Thread.run()

cancel

public boolean cancel()
Cancels this timer task. If the task has been scheduled for one-time execution and has not yet run, or has not yet been scheduled, it will never run. If the task has been scheduled for repeated execution, it will never run again. (If the task is running when this call occurs, the task will run to completion, but will never run again.) 取消该计时任务。如果任务已被安排为一次执行并且还没有运行或者还没有被安排,它将不会运行。如果任务被安排为重复执行,它将不会再次运行。(如果调用时任务正在运行,任务将运行至结束,但不会再次运行。)

Note that calling this method from within the run method of a repeating timer task absolutely guarantees that the timer task will not run again. 注意在一个重复计时任务的run方法调用此方法可以绝对担保计时任务不会再次运行。

This method may be called repeatedly; the second and subsequent calls have no effect. 该方法可以重复调用,但第二次及其后的调用不起作用。

Returns:
true if this task is scheduled for one-time execution and has not yet run, or this task is scheduled for repeated execution. Returns false if the task was scheduled for one-time execution and has already run, or if the task was never scheduled, or if the task was already cancelled. (Loosely speaking, this method returns true if it prevents one or more scheduled executions from taking place.) 如果任务被安排为一次执行而没有运行,或者被安排为重复执行,返回true。 如果任务被安排为一次执行而已经运行,或者任务还没有被安排,或者任务已经被取消,返回false。 (粗略地讲,如果方法阻止一次或多次被安排执行的发生,返回true。)

scheduledExecutionTime

public long scheduledExecutionTime()
Returns the scheduled execution time of the most recent actual execution of this task. (If this method is invoked while task execution is in progress, the return value is the scheduled execution time of the ongoing task execution.) 返回该任务最近实际执行所安排的执行时间。(如果方法调用时任务执行正在进行,那么返回正在进行任务执行的安排执行时间值。)

This method is typically invoked from within a task's run method, to determine whether the current execution of the task is sufficiently timely to warrant performing the scheduled activity: 该方法通常在任务的run方法中调用,用来确定是否当前执行的任务是否足够及时保证执行安排的动作:

   public void run() {       if (System.currentTimeMillis() - scheduledExecutionTime() >=           MAX_TARDINESS)               return;  // Too late; skip this execution.       // Perform the task   } 
This method is typically not used in conjunction with fixed-delay execution repeating tasks, as their scheduled execution times are allowed to drift over time, and so are not terribly significant. 该方法通常不在固定延迟的执行重复任务的连接中使用,因为 它们的执行时间允许超时,所以意义不明显。

Returns:
the time at which the most recent execution of this task was scheduled to occur, in the format returned by Date.getTime(). The return value is undefined if the task has yet to commence its first execution. 任务的最近执行被安排的时间,以格式Date.getTime()返回。如果任务还未开始它的第一次执行, 返回值不确定。
See Also:
Date.getTime()

Overview Package  Class Use Tree Deprecated Index Help JavaTM 2 Platform
Std. Ed. v1.4.2
 PREV CLASS   NEXT CLASSFRAMES    NO FRAMES     All Classes SUMMARY: NESTED | FIELD | CONSTR | METHODDETAIL: FIELD | CONSTR | METHOD
Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.