I am using java.Util.Timer library for schedule my job.
I wanna call my function at 22:00 every sunday. So my code is like :
rspServer = new RSPServer();
Calendar scheduleStartTime = Calendar.getInstance();
scheduleStartTime.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
scheduleStartTime.set(Calendar.HOUR_OF_DAY, 22);
scheduleStartTime.set(Calendar.MINUTE, 0);
scheduleStartTime.set(Calendar.SECOND, 0);
scheduleStartTime.set(Calendar.MILLISECOND, 0);
rspServer.startScheduler(Class.forName("xx.xx.xx.xx.RSP.RSPServer"),rspServer, "PopulateModels", scheduleStartTime, 7 * 24 * 60 * 60 * 1000);
I deployed that code and restarted websphere server at thursday. I was expecting that function will be start at sunday. But it didn't fire. There is no error or out log in the server.
I tried that
I updated the start time as monday 11:00 am. And restarted server at 10:40 am on monday. After 20 minutes, my function worked at 11:00 am as expected. But if I restart my server at thursday and set the start time as sunday it did not fire.
Is there a kind of idle thread kill time or sth else in webshere server? What could be the reason for this?
here is my startScheduler function
public void startScheduler(final Class<?> serverClass, final Object server,
final String methodName, Calendar _startAfterTime, int _repeatAfterTime) {
timer = new Timer();
TimerTask timerTask = new TimerTask() {
private java.lang.reflect.Method method;
@Override
public void run() {
try {
method = serverClass.getMethod(methodName);
method.invoke(server);
} catch (Exception e) {
// TODO Auto-generated catch block
System.err.println("Error!");
e.printStackTrace();
}
}
};
timer.schedule(timerTask, _startAfterTime.getTime(), _repeatAfterTime);
}