Question : Java Timer Task

Hi,

My requirement is to schedule the timer at 11 AM and repeat it after every minute.

Here is my code.

         Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("EST"));
         cal.set(Calendar.DAY_OF_WEEK, cal.get(Calendar.DAY_OF_WEEK));
         cal.set(Calendar.HOUR_OF_DAY, 11);
         cal.set(Calendar.MINUTE, 0);
         cal.set(Calendar.SECOND, 0);
         cal.set(Calendar.MILLISECOND, 0);
         
         Date stTime = cal.getTime();
         
         if (!stTime.before(new Date()))
             new Timer(true).scheduleAtFixedRate(new ImportTimerUtil(), stTime, 60000);

The timer is scheduled when I click a button.

The problem is the timer is started immediately after clicking a button(clicked the button at 10:30 AM). It is starting after evey 1 minute delay. It is not supposed to start immediately. It is supposed to start at 11:00 AM and after every minute from then.

Thanks...

Answer : Java Timer Task

Fortunately, archinpalli the comments above should remove any confusion on this issue:

a. If you hadn't set a timezone of any kind, you would have been OK
b. If you do want to set one for your location, you must use America/New_York, not EST, since, despite what you might think, the latter is *not* your time zone, as it doesn't do daylight savings time, and you do
Random Solutions  
 
programming4us programming4us