2015-05-04 104 views
-3

我是一名初學java程序員,我在網上看到關於我的projet的代碼。 但我不明白它的作用?任何人都能解釋? 什麼是1000s?爲初學者解釋java代碼

private Timer timer = null; 
private int timeWorking; 

private void xxxxxxxxxxx() { 

    if (timer == null) { 

     timer = new Timer("Time"); 
     timer.schedule(new TimerTask() { 

      @Override 
      public void run() { 

       timeWorking++; 

      } 

     }, 1000, 1000); 

    } 

} 
+0

毫秒或一秒鐘。它每秒調度一次回調(到'TimerTask'),並有第二次延遲。查看[Timer的JavaDocs](https://docs.oracle.com/javase/7/docs/api/java/util/Timer.html)以獲取更多詳細信息 – MadProgrammer

+0

檢查Timer類的api 。 – Stultuske

+0

...位於https://docs.oracle.com/javase/8/docs/api/java/util/Timer.html#schedule-java.util.TimerTask-long-long- – gustafc

回答

0

的看到Timer.schedule的documentation()

task - task to be scheduled.delay - 
delay in milliseconds before task is to be executed.period - 
time in milliseconds between successive task executions. 
0

java.util.Timer documentation參見

第一個 「1000」 是指延遲 - 以毫秒爲單位的延遲任務之前將被執行。 第二個「1000」表示期間 - 連續任務執行之間的時間(以毫秒爲單位)。

0

public void schedule(TimerTask task,long delay,long period)您正在調用此方法,延遲時間爲1000ms,週期爲1000ms。

+0

我已經編輯了我的答案,因此謝謝。 – Jessica

+0

謝謝@Jessica –