Reputation: 23
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.
Upvotes: 0
Views: 65
Reputation: 1154
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.
Upvotes: 0