Releasing Java 7 WatchService Resources

I am using Java 7 WatchService to browse directories. I am constantly changing which directories I am browsing. I came across an exception:

java.io.IOException: Network BIOS command limit reached.

after 50 directories. I'm sure I call close () for every WatchService that I create before creating a new one.

Does anyone know the right way to issue WatchService so you don't run into this limit?

Thank,

Dave

+5
source share
2 answers

, , , close() . , , , , , . , . WatchService - finally; .

WatchService ws = ...
try {
    // use it ...
} finally {
    ws.close();
}

Java 7 " ".

try (WatchService ws = ...) {
    // use it ...
}

WatchService , O/S, .


, Java WatchService.

+3

Javadoc, WatchService, () .

.register , , WatchKey. WatchKeys , , ConcurrentMap Path.

, cancel() WatchKey .

WatchService

Path.Register

WatchKey

+1

All Articles