Scheduler to run a program in java Views : 907
Tagged in : JSP-Java
0 0
Send mail
The bellow code will run the java code or function at a schedule time.

import java.util.Timer;
import java.util.TimerTask;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Date;

public final class Schedule extends TimerTask {
public static void main (String arg[] ) {
TimerTask report = new Schedule();
Timer timer = new Timer();
timer.scheduleAtFixedRate(report, getTomorrowMorning4am(), fONCE_PER_DAY);
public void run(){//the function will run at the scheduled time
System.out.println("Sampling for urlstatus to repository");
private final static long fONCE_PER_DAY = 1000*60*60*24;
private final static int fONE_DAY = 2;
private final static int fFOUR_AM = 14;
private final static int fZERO_MINUTES = 22;
private static Date getTomorrowMorning4am(){
Calendar tomorrow = new GregorianCalendar();
tomorrow.add(Calendar.DATE, fONE_DAY);
Calendar result = new GregorianCalendar(
return result.getTime();
By Vinoth, On - 2009-03-16

    Login to add Comments .