1)
See the samples below.import java.util.*;class MyTimeTask extends TimerTask {
  public static final int MAX_TARDINESS = 10000;
  private String name;
  
  public MyTimeTask(String name) {
    this.name = name;
  }
  
  public void run() {
    if (System.currentTimeMillis() - scheduledExecutionTime() >= MAX_TARDINESS) {
      return;  // Too late; skip this execution.
    }
    System.out.println("name = " + name);
    // Perform the task
  }
}public class TestProg {
  public static void main(String[] args) throws Exception {
    Timer timer = new Timer();
    timer.schedule(new MyTimeTask("helo universe"), 1000);
    Thread.sleep(2000);
  }
}2) System.getCurrentTimeMills();