文件夹扫描服务的设计

发布于 2024-12-27 08:05:10 字数 136 浏览 3 评论 0原文

我们有一个旧的 java 应用程序包装为服务,本质上是一个 while 循环,它迭代文件夹以查找正在创建的新文件。

除了与大文件有点不一致之外,它运行良好,但让我想知道这是否仍然是一个非常基本的方法,或者它是否是“查找更新”应用程序的唯一方法

We have an old java app wrapped as a service that essentially is a while loop, which iterates through folders looking for new files being created.

Apart of being a little inconsistent with big files, it works well, but makes me wonder if this is still a very basic approach or if it is the only approach when it comes to "look for updates" apps

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷了相思 2025-01-03 08:05:10

如果您使用的是 Java 7,则可以使用 WatchService API这篇文章提供了很好的介绍。

如果操作系统支持,WatchService 比轮询更有效;如果操作系统不支持任何更高级的方式来监视文件系统的更改,它会自动回退到轮询。

If you are using Java 7, you can use the WatchService API. This article provides a good introduction.

WatchService is more efficient than polling if the OS supports it, and it will automatically fall back to polling if the OS does not support any more advanced way of watching the file system for changes.

淡写薰衣草的香 2025-01-03 08:05:10

如果您不必坚持使用 Java,您可以尝试在服务中使用 .NET 的 FileSystemWatcher 类,而不是您的 java 实现。

If you don't have to stick with Java, you might try .NET's FileSystemWatcher class inside of the service instead of your java implementation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文