Mohammad Mohammad - 1 year ago 103
Java Question

how to do a job based on time that user has entered

I have some entities in database. Every entity have a field called time.
the time field has been entered from user side. I want to call a method on that time.
For example imagine a system that will call to your phone in specific time that you have set before.
I know A solution is to use a tread that checks the time field in database every second, but What is the best solution?

Answer Source

Have a look at Spring-Scheduler here. There you can define your own Scheduler instance. This has a method called schedule() which can be called with a specific task and a (Cron)Trigger. On the time the user saves the entity with the given time you can create a new (Cron)Trigger to schedule the task.

scheduler.schedule(task, new CronTrigger("0 15 9-17 * * MON-FRI"));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download