Hi Jeff, you should be able to get a bit closer to the problem if you
eliminate the firstTime field. You probably find the timer is not run
due to the value of this field - try setting the first time to say 10
seconds from current system time (long + 1000 * x x etc) and try it
then - you may discover that the time you are setting the Calendar to is
in the past or somewhere else... my 2 rands worth.. CARL
[EMAIL PROTECTED] wrote:
Hi guys
I'm trying to schedule an MQSeries queue poller, to run from 7am to 7pm
,Monday to Friday, with a delay of an hour.My code looks like this :
Calendar date = Calendar.getInstance();
date.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
date.set(Calendar.HOUR_OF_DAY, 7);
date.set(Calendar.MINUTE, 0);
date.set(Calendar.SECOND, 0);
date.set(Calendar.MILLISECOND, 0);
Date firstTime = date.getTime();
this.timer = new Timer();
this.task = new TimerTask() {
public void run() {
try {
MQMessageReader mqMessageReader =
MQMessageReader.getInstance();
GregorianCalendar calendar = new GregorianCalendar();
if (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY
&&
calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
if (calendar.get(Calendar.HOUR_OF_DAY) >= SEVEN_AM &&
calendar.get(Calendar.HOUR_OF_DAY) < SEVEN_PM) {
if (mqMessageReader.pollAndTransmit()) {
pause();
log.log("INFO", "*** Message Poller:
Pausing for message
read...");
HashMap data = new HashMap();
data.put("resume", new Boolean(true));
data.put("report", new Report(format(new
java.util.Date())));
processMessagesNotification(data);
boolean resume = ((Boolean)
data.get("resume")).booleanValue();
data = null;
log.log("INFO", "*** Message Poller:
Nullified data and
associated objects under processing.");
resume();
log.log("INFO", "*** Message Poller: Polling may
resume is " +
resume);
}
}
}
}catch (Exception e) {
log.log("SEVERE", "*** Message Poller: Encountered an
exception
while polling input queue ");
e.printStackTrace();
}
}
};
timer.schedule(task, firstTime, period);
When I test with my system clock set to any day from Monday to Friday ,
the poller polls the queue hourly as I want it to.When I change my
system clock to eg Saturday or Sunday , the poller stops polling as
expected.The trouble seem to start when I reset my system clock back to
any day from Monday to Friday , so that the polling resumes.It doesn't
resume and it seems like the task's run() method is never called
anymore.Where am I going wrong?Why isn't the polling resuming on a
Monday after stopping on a Saturday ?
jeff
Registered Linux user number 366042