Whether you hang onto this reference or not is up to you, because the WatchService returns the relevant WatchKey to you when an event is triggered.
是否挂接到这个引用由您决定,因为触发事件后,WatchService 会返回相关的 WatchKey。
When you're done with a particular WatchKey and the events it's registered for, you can cancel its registration with the WatchService simply by calling its cancel method.
当您在处理特定WatchKey及其所注册的事件时,可以很简单地通过调用cancel方法,来取消其在WatchService的注册。
应用推荐