java 7目录监控问题 [英] java 7 directory monitoring questions

查看:123
本文介绍了java 7目录监控问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚看到一个令人敬畏的功能与java 7,目录观察者。它会告诉你什么时候改变目录而没有轮询目录。



1。)但是它说如果文件系统不支持注册,它将返回到轮询用于改变事件。所有典型的linux和windows文件系统(extX,ntfs,reiserXXX,jsf,zfs)是否支持此功能?



2。)将目录中的文件重命名为创建或更改事件?还是一个删除和一个创建?我可以在一个系统上测试它,但对于所有的文件系统来说都是一样的。

解决方案

谈论 WatchService



ENTRY_CREATE 事件说,如果创建新文件或将文件重命名为目录,则会感知到新的条目。如果一个文件被重命名并且保存在同一个目录中,那么它就没有指定什么事件被触发。



这个措辞也指出这个服务是基于操作系统还是轮询依赖于实现。我怀疑这是JRE的实现,所以即使你知道一个特定的操作系统支持它,这不是保证该服务将使用操作系统级功能或诉诸于轮询。实际上,该服务根本没有提供任何方式来判断是使用轮询还是操作系统级功能。



API定义的操作也不行为像一个听众。 WatchService确实会自动观看,但要获取发生的事件列表,您仍然必须手动请求从服务中看到的事件。当新事件出现时,似乎没有提供任何钩子来自动调用。


I just saw an awesome feature with java 7, the directory watcher. It'll tell you when something changed in a directory without polling the directory.

1.) But it says it falls back to polling if the filesystem doesn't support registering for change events. Do all typical linux and windows filesystems(extX,ntfs,reiserXXX,jsf,zfs) support this feature?

2.) Is renaming a file inside a directory a create or a change event? Or is that one delete and one create? I can test it on one system, but will it then be the same for all filesystems?

解决方案

It looks like you're talking about the WatchService.

The wording of the ENTRY_CREATE event says that a new entry would be perceived if a new file is created or a file is renamed into the directory. It lacks specification of what events are fired if a file is renamed and remains in the same directory.

The wording also states that whether the service is based on the operating system or polling is implementation dependent. I suspect that's implementation by the JRE, so even if you know a particular OS supports it, it's not a guarantee that the service will use the OS-level functionality or resort to polling. In fact, the service does not provide any way to tell whether it is using polling or an OS-level feature at all.

The operations the API define also do not behave like a Listener. The WatchService does do automatic watching, but to acquire the list of events which happen, you still have to manually request the seen events from the service. It doesn't appear to provide any hooks to automatically get called when a new event is present.

这篇关于java 7目录监控问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆