Which statement is true?

An application is waiting for notification of changes to a tmp directory using the following code
statements:
Path dir = Paths.get(“tmp”)
WatchKey key = dir.register (watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY) ;
In the tmp directory, the user renames the file testA to testB,
Which statement is true?

An application is waiting for notification of changes to a tmp directory using the following code
statements:
Path dir = Paths.get(“tmp”)
WatchKey key = dir.register (watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY) ;
In the tmp directory, the user renames the file testA to testB,
Which statement is true?

A.
The events received and the order of events are consistent across all platforms.

B.
The events received and the order of events are consistent across all Microsoft Windows
versions.

C.
The events received and the order of events are consistent across all UNIX platforms.

D.
The events received and the order of events are platform dependent.

Explanation:

Most file system implementations have native support for file change notification. The
WatchService API takesadvantage of this support where available.
However, when a file system does not support this mechanism, the WatchService will poll the file
system,waiting for events.
Note:
WatchKey : When a Watchable entity is registered with a WatchService a key which is a
WatchKey isgenerated. Initially the key is in ready state waiting to be notified of any events on the
Watchable entity. Oncean event occurs the key goes into signaled state and allows to access the
events using its pollEvents method.

After processing the poll events the key has to be reset by invoking its reset method.
Reference: The Java Tutorials,Watching a Directory for Changes



Leave a Reply 7

Your email address will not be published. Required fields are marked *


Tim

Tim

I think it should be D. By the “Platform dependencies” section in the WatchService API (http://docs.oracle.com/javase/8/docs/api/java/nio/file/WatchService.html), it says:

“The implementation that observes events from the file system is intended to map directly on to the native file event notification facility where available, or to use a primitive mechanism, such as polling, when a native facility is not available. Consequently, many of the details on how events are detected, their timeliness, and whether their ordering is preserved are highly implementation specific. For example, when a file in a watched directory is modified then it may result in a single ENTRY_MODIFY event in some implementations but several events in other implementations. Short-lived files (meaning files that are deleted very quickly after they are created) may not be detected by primitive implementations that periodically poll the file system to detect changes.”

Luiz

Luiz

I agree. The answer is D

Humberto Bañuelos Flores

Humberto Bañuelos Flores

+1

gelete

gelete

D

OCA/OCP Java SE7 Programmer I and II Study Guide (Kathy Sierra and Bert Bates)
529 Two-Minute Drill:

PathMatcher and WatchService use FileSystem-specific implementations.