我的问题是我在我的网站上实现了一个功能,当我按下按钮时会搜索特定推文。我想让它自动化,这样,每隔两分钟就会一次又一次地调用该函数,无论是否有人使用该网站。如何在java中执行此操作? Spring解决方案更好
答案 0 :(得分:0)
您可以使用Spring计划(请参阅documentation here)
来自doc:
<context:component-scan base-package="some.package" />
<task:annotation-driven executor="myExecutor" scheduler="myScheduler"/>
<task:executor id="myExecutor" pool-size="5"/>
<task:scheduler id="myScheduler" pool-size="10"/>
@Component
public class SomeBean {
@Scheduled(fixedRate=5000)
public void doSomething() {
// something that should execute periodically
}
}