Java Data Type How to - Schedule task for a specific time


We would like to know how to schedule task for a specific time.


import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Timer;
import java.util.TimerTask;
/*ww w  .j  av  a m*/
public final class Main extends TimerTask {
  public static void main(String... arguments) {
    TimerTask fetchMail = new Main();
    // perform the task once a day at 4 a.m., starting tomorrow morning
    Timer timer = new Timer();
    timer.scheduleAtFixedRate(fetchMail, getTomorrowMorning4am(), fONCE_PER_DAY);
  public void run() {
  private final static long fONCE_PER_DAY = 1000 * 60 * 60 * 24;

  private final static int fONE_DAY = 1;
  private final static int fFOUR_AM = 4;
  private final static int fZERO_MINUTES = 0;

  private static Date getTomorrowMorning4am() {
    Calendar tomorrow = new GregorianCalendar();
    tomorrow.add(Calendar.DATE, fONE_DAY);
    Calendar result = new GregorianCalendar(tomorrow.get(Calendar.YEAR),
        tomorrow.get(Calendar.MONTH), tomorrow.get(Calendar.DATE), fFOUR_AM,
    return result.getTime();