我想每 30 秒发送一次通知。我已经使用 TimerTask 安排了我的任务,但它不工作。为什么会这样?我的搜索器如下所示:
@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;
}