當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java TimerTask scheduledExecutionTime()用法及代碼示例


scheduleExecutionTime() 是 TimerTask 類的方法。此方法返回最近執行的任務的給定執行時間。

用法

public long scheduledExecutionTime()

返回

它返回最近執行的任務的執行時間。

例子1

import java.util.*;
public class TimerTaskScheduledExecutionTimeExample1{
   public static void main(String[] args) {
// creating timer task, timer
Timer t = new Timer();
TimerTask tt = new TimerTask() {
    @Override
    public void run() {
       for(int i=1; i<=10;i++)
       {
        System.out.println("Task Timer is on");
        }
    };
};
    t.scheduleAtFixedRate(tt, new Date(), 1000);
    System.out.println("Time is:"+tt.scheduledExecutionTime());
   }
}

輸出:

Task Timer is on
Task Timer is on
Task Timer is on
Task Timer is on
Task Timer is on
Task Timer is on
Task Timer is on
Task Timer is on
Task Timer is on
Task Timer is on
Time is:1533927090455
Task Timer is on
Task Timer is on
Task Timer is on
.
.
.

例子2

import java.util.*;
public class TimerTaskScheduledExecutionTimeExample2{
   public static void main(String[] args) {
// creating timer task, timer
Timer t = new Timer();
TimerTask tt = new TimerTask() {
    @Override
    public void run() {
        System.out.println("Task Timer is on"); 
    };
};
    t.scheduleAtFixedRate(tt, new Date(), 1000);
        System.out.println("Time is:"+tt.scheduledExecutionTime());
   }
}

輸出:

Time is:1534099265658
Task Timer is on
Task Timer is on
Task Timer is on
Task Timer is on
Task Timer is on
Task Timer is on
.
..
.
.
.






相關用法


注:本文由純淨天空篩選整理自 Java TimerTask scheduledExecutionTime() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。