Results 1 to 3 of 3
Thread: Job Scheduling in java
- 09-13-2010, 05:00 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 16
- Rep Power
- 0
Job Scheduling 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:16 PM #2
Create two calendar objects, one for each date. Use the getTime method on each and subtract.the time between the two dates
-
Please do not double post the same question in multiple forums. I'm locking your other thread.
Similar Threads
-
* Help: Java Code For Cpu Scheduling Algorithm
By coldvoice05 in forum AWT / SwingReplies: 2Last Post: 03-10-2010, 03:43 PM -
* Help: Java Code For Cpu Scheduling Algorithm
By coldvoice05 in forum New To JavaReplies: 1Last Post: 07-15-2009, 04:30 AM -
Quartz scheduling in EJB3
By Niveditha in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 06-30-2008, 08:34 AM -
Scheduling tasks using Threads
By Java Tip in forum Java TipReplies: 0Last Post: 12-11-2007, 10:24 AM -
Scheduling a task
By bugger in forum Advanced JavaReplies: 3Last Post: 12-04-2007, 12:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks