crontrigger - How to trigger events in java at specific date and time? -
i need send sms few mobile nos @ specific date , time. e.g. have list of dates , times , list of corresponding mobile nos. below.
date mobile 10th april 9 1234567890 10th april 11 9987123456,9987123457 11th april 3.30 pm 9987123456 and on.
i know, java has cron schedulers can run @ specific schedule.
http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html
i can run job can keep on checking time , if current time matches time in above list, send sms.
but in case have keep on checking time.
is there way, can fire events/sms directly @ given time. registering jobs each of date time , firing @ time instead of having job runs continuously check date times ?
you can use scheduledexecutorservice. see tutorial.
private class smssendertask implement runnable { private string text; private list<string> phonenumbers; public void run() { (string number : phonenumbers) { sendsms(number, text); } } } scheduledexecutorservice service = executors.newscheduledthreadpool(1); (date d : dates) { long millis = d.gettime() - system.currenttimemillis(); service.schedule(new smssendertask(text, phonenumbers), millis, timeunit.milliseconds); }
Comments
Post a Comment