I have a task to develop a simple app that handle requests (user sends requests and other accept or reject) and I need to develop a background task that cancels all pending requests that exceed 2 minutes without receiving user accept or reject.
What is the best technique to develop this ?
I'm using Java spring boot and MySQL for the database
CodePudding user response:
I would reccomend mysql scheduled job that works every minute and do some kind of operation like :
update task set status = 'reject' where taskdate < DATE_SUB(NOW(), INTERVAL 2 MINUTE)
you can find detailed description here
CodePudding user response:
What you want is the Spring @Scheduled
annotation.
@Scheduled(fixedDelay = 1000)
public void scheduleFixedDelayTask() {
System.out.println(
"Fixed delay task - " System.currentTimeMillis() / 1000);
}
Here are the details about how to setup and configure it