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 Watch Service API takes advantage of this support where available. However, when a file system does not support this mechanism, the Watch Service 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 is generated. Initially the key is in ready state waiting to be notified of any events on the Watchable entity. Once an 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 2

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


Tim

Tim

It should be D. Accroding to the API document for WatchService:

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.