mercredi 31 octobre 2018

Java run event at certain time in future

I am designing a java web app using jersey in which i having a date time field, "future_time" in mysql db. I am also a having a status field in the same table set to pending. I want to update the status field to completed in db if the current time >= future_time. It is like I want to schedule a event.

Secondly if current_ time < future_time and if i updated the future_time value, i would i like to reschedule the previous event.

Currently, whenever i fetch status field i check if it is pending, if it is pending then i check if future_time<= current_time, if so then i update the status field in db to completed. But there is a problem in this. This will only update the status field when i fetch it. So if i fetch the status field after a long time(after future_time) , then it will be update at that instant, saving incorrect records in db.

Can anyone suggest me a better way to achieve this?




Aucun commentaire:

Enregistrer un commentaire