简体   繁体   English

如何在服务器上每x分钟运行一次算法?

[英]How to run an algorithm every x minutes on a Server?

I've created a clustering algorithm in Java that reads from a collection in a Mongo database, makes its computations and then writes to a new collection in the same database. 我在Java中创建了一个聚类算法,它从Mongo数据库中的一个集合中读取,进行计算,然后写入同一数据库中的一个新集合。 Now, I need this algorithm to run every 30 minutes in the server. 现在,我需要这个算法在服务器中每30分钟运行一次。 What could I use to do so? 我可以用它做什么?

你可以使用石英调度程序每30分钟安排一次算法,你可以在这里找到一个很好的石英调度程序教程。

If you're using JavaEE, you could use the @Schedule annotation. 如果您使用的是JavaEE,则可以使用@Schedule注释。

Take a look at the API here . 这里查看API It saves you from using a dependency in your project. 它可以避免在项目中使用依赖项。


Update: 更新:

If you're using JavaSE, maybe a Timer can help you. 如果你正在使用JavaSE,也许Timer可以帮助你。

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

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