Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2010
    Rep Power

    Default Job scheduling using timers in java

    I am trying to schedule a job using java. By using timer class i can able to specify to schedule at particular time. But I am looking to specify between two dates and also need to specify the time between the two dates. Could someone help me to say how we can use timer class and schedule the task between two dates ?

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

    public class Scheduler {

    public static Object[] getInput(){
    Properties properties = new Properties();
    try {
    properties.load(new FileInputStream("./property/"));
    } catch (IOException e) {

    String[] datetime = properties.getProperty("startdatetime").split(":") ;

    Calendar date = Calendar.getInstance();
    Calendar now = Calendar.getInstance();

    date.set(Calendar.DATE, Integer.parseInt(datetime[0]));
    date.set(Calendar.MONTH, Integer.parseInt(datetime[1]));
    date.set(Calendar.YEAR, Integer.parseInt(datetime[2]));

    date.set(Calendar.HOUR, Integer.parseInt(datetime[3]));
    date.set(Calendar.MINUTE, Integer.parseInt(datetime[4]));
    date.set(Calendar.SECOND, Integer.parseInt(datetime[5]));
    date.set(Calendar.MILLISECOND, Integer.parseInt(datetime[6]));

    // Schedule to run every Sunday in midnight
    // date.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY);
    // you can find lot of other options for days and months in calendar object

    date = now;

    long delaySeconds = Long.parseLong(properties.getProperty("delaysecond s"));
    Long delayInSeconds = new Long(delaySeconds);
    return new Object[]{date.getTime(),delayInSeconds};

    public void schedule(TimerTask tt){
    Timer timer = new Timer();
    Object[] input = getInput();
    // timer.schedule(tt,(Date)input[0],(Long)input[1]);

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

Similar Threads

  1. I need help with timers
    By Chris Rice in forum New To Java
    Replies: 15
    Last Post: 09-04-2013, 08:02 PM
  2. Job Scheduling in java
    By umapathy_sekar in forum Advanced Java
    Replies: 2
    Last Post: 09-13-2010, 06:27 PM
  3. * Help: Java Code For Cpu Scheduling Algorithm
    By coldvoice05 in forum AWT / Swing
    Replies: 2
    Last Post: 03-10-2010, 04:43 PM
  4. * Help: Java Code For Cpu Scheduling Algorithm
    By coldvoice05 in forum New To Java
    Replies: 1
    Last Post: 07-15-2009, 05:30 AM
  5. Question on swing timers
    By Samgetsmoney in forum New To Java
    Replies: 5
    Last Post: 02-20-2009, 08:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts