Reputation: 5313
I am working on a Spring-MVC application in which I am using scheduling to delete extra stuff which is not necessary. Unfortunately, my scheduled method did not fire. Can anyone tell me what I did wrong.
Here is the code :
@Repository
@Transactional
@EnableScheduling
public class NotificationDAOImpl implements NotificationDAO{
@Override
@Scheduled(cron = "0 3 3 * * ?")
public void deleteNotificationsAutoMagically(){
session=this.sessionFactory.getCurrentSession();
long now = System.currentTimeMillis();
long nowMinus1Week = now - (1000 * 60 * 60 * 24 * 3);
Timestamp nowMinus1WeekAsTimeStamp = new Timestamp(nowMinus1Week);
Query query = session.createQuery("delete from NoteLock as nl where nl.timestamp < :limit and nl.read=:true");
query.setParameter("limit", nowMinus1WeekAsTimeStamp);
query.executeUpdate();
session.flush();
}
}
I know parameter name is for 1 week, but I am deleting it in 3 days. I just copied the code .. :D Any help would be nice. Thanks.
Upvotes: 1
Views: 350
Reputation: 3400
That cron expression looks like it will run at 3 O' clock on 3rd of every month.
If you want to run every 3 minutes, you can use the below expression.
0 0/3 * 1/1 * ? *
You can use cronmaker for generating expressions
To verify whether the cron expressions you create, visit this page
Upvotes: 1