Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Java Timer Task

Avatar of archinpalli
archinpalli asked on
25 Comments1 Solution602 ViewsLast Modified:

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.

Avatar of CEHJ
This problem has been solved!
Unlock 1 Answer and 25 Comments.
See Answers