Anand Kadhi
Anand Kadhi

Reputation: 1878

@Scheduled being called at server startup

We are using JBoss App server 7.0.0, Spring 4.1.6 , Hibernate-JPA 2.0 in our project. I want to persist data at configured interval specified in the properties. For this i am using spring scheduling
@Scheduled(fixedRateString = "${db.commit.interval}"),
public void commitToDB()
But one problem i am facing is this method is called automatically on server startup meaning if i scheduled this method to be called every 5th minute , i expect that after server startup at 12:00:00 this method should be called at 12:00:05 but it is being called at 12:00:00 only (i.e on server startup). Can any one suggest is it a problem or am i missing something ?

Upvotes: 0

Views: 1632

Answers (1)

Arnaud
Arnaud

Reputation: 17524

Try to add a initialDelayString property.

Also, give it the same value as your fixed rate.

However, if what you want is to have it running exactly at the fifth minute of an hour, the tenth minute and so on, consider using a cron expression in your annotation .

Upvotes: 1

Related Questions