繁体   English   中英

TimerTask 在 vespa 的 Searcher 中不起作用

[英]TimerTask is not working in Searcher in vespa

我想每 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;
}

search() 方法是在每个请求的基础上调用的,并且您正在为每个请求创建一个新的 Timer 实例,该实例在搜索方法返回后一段时间被 Java VM 垃圾回收,因为没有对其的引用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM