I want to send notifications after every 30 seconds. I have scheduled my task using TimerTask but it is not working. Why is it so? My Searcher is given below:
@Override
public Result search(Query query, Execution execution) {
// pass it down the chain to get a result
Result result = execution.search(query);
execution.fill(result);
//the Date and time at which you want to execute
DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = dateFormatter.parse("2018-10-17 16:20:00");
} catch (ParseException e) {
e.printStackTrace();
}
//Now create the time and schedule it
Timer timer = new Timer();
assert date != null;
timer.schedule(new TimerTask() {
@Override
public void run() {
sendNotification();
}
}, date, 30000);
// return the result up the chain
return result;
}