scheduleAtFixRate runs every 10 minutes instead of hourly

253 views Asked by At

I have created a job to run every hour as follows

public class BackgroundJobManager implements ServletContextListener {

    private ScheduledExecutorService scheduler;

    public void contextInitialized(ServletContextEvent sce) { 
        .
        .
        scheduler = Executors.newSingleThreadScheduledExecutor();
        scheduler.scheduleAtFixedRate(new HourlyJob(), 0, 1, TimeUnit.HOURS);
        .
        .
    }
}

But HourlyJob() is executing every 10 minutes instead of hourly. Not sure what wrong I am doing here.

Does anyone know why the TimeUnit.HOURS is not considered as expected?

1

There are 1 answers

1
Jimmy On

It may be an annotation for scheduled task's method @Schedule

@Schedule(hour = "*")
public void doHourlyJob() {
    ....
}