简体   繁体   中英

Create a scheduled task which will be processed after the certain time

I'm working on a course project using Spring Boot and Hibernate. Currently, I have a Trip model, which contains information about Starting Place, Destination, Starting Date, Estimated Days, ... . My application allows its user create new trip with specified starting date. When the trip is created, its status is set to WAITING by default. My issue is when the time (starting date) comes, I want to the status is changed to IN_PROGRESS automatically. I wonder how to implement it in Spring Boot. Some idea that I has found is using @Scheduled annotation, but what if I can load the specific time from Database, then add it to the annotation by Java code.

Some idea that I has found is using @Scheduled annotation, but what if I can load the specific time from Database, then add it to the annotation by Java code.

I'm looking forward to hearing from all of you. Thanks for reading.

but what if I can load the specific time from Database, then add it to the annotation by Java code.

That's not what you would do.

Instead, define a scheduled task in the code that runs at a pre-determined frequency, for instance once per day at midnight. In the task, get all the trips that start on a given day and update the status (preferably in batch).

You can use @Scheduled to accomplish this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM