I'm trying to make a Listener (or something like that?) that will start a specific event when a date field from a database row is the same as the current time. Of course I can trigger every second to check if the date/time is the same as the current, but I think that is quite expansive. There should be a better alternative..
What I trying to do is the following: I have several (for example football) matches scheduled in my database. At the specific time when the match should start, I will start a event in my Java app. This could be 1 or more matches at that time.
I understand that you are trying to schedule execution of future events in java app not in database.
You should consider using ScheduledExecutorService
method schedule
to delay execution of task to specific point in time.
The only problem you have to solve is how you synchronize task in database with this in schedule.
EDIT: If you keep map with taskID->ScheduledFuture object returned you can easily call cancel on the object to remove task. But you have to add some kind of last-modification column to detect new and updated tasks and query database to check if there are not any new tasks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With