Results 1 to 2 of 2
- 09-13-2010, 05:03 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 16
- Rep Power
- 0
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.io.FileInputStream;
import java.io.IOException;
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/SchedulerProperties.properties"));
System.out.println(properties);
} catch (IOException e) {
e.printStackTrace();
}
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
if(date.before(now)){
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();
System.out.println((Long)input[1]);
// timer.schedule(tt,(Date)input[0],(Long)input[1]);
timer.schedule(tt,(Date)input[0]);
//timer.schedule(tt,(Date)input[0],delaySeconds);
}
}
- 09-13-2010, 05:18 PM #2
Similar Threads
-
Job Scheduling in java
By umapathy_sekar in forum Advanced JavaReplies: 2Last Post: 09-13-2010, 05:27 PM -
* Help: Java Code For Cpu Scheduling Algorithm
By coldvoice05 in forum AWT / SwingReplies: 2Last Post: 03-10-2010, 03:43 PM -
I need help with timers
By Chris Rice in forum New To JavaReplies: 14Last Post: 03-07-2010, 09:04 PM -
* Help: Java Code For Cpu Scheduling Algorithm
By coldvoice05 in forum New To JavaReplies: 1Last Post: 07-15-2009, 04:30 AM -
Question on swing timers
By Samgetsmoney in forum New To JavaReplies: 5Last Post: 02-20-2009, 07:34 AM


LinkBack URL
About LinkBacks

Bookmarks