1Z0-805 · Question #33
Which statement is true about the take method defined in the WatchService interface?
The correct answer is C. Retrieves and removes the next watch key: waits if no key is yet present. The WatchKey take() method retrieves and removes next watch key, waiting if none are yet Note: A watch service that watches registered objects for changes and events. For example a file manager may use a watch service to monitor a directory for changes so that it can update its…
Question
Which statement is true about the take method defined in the WatchService interface?
Options
- ARetrieves and removes the next watch key, or returns null of none are present.
- BRetrieves and removes the next watch key. If a queued key is not immediately available, the program
- CRetrieves and removes the next watch key: waits if no key is yet present.
- DRetrieves and removes all pending events for the watch key, returning a list of the events that were retrieved.
How the community answered
(45 responses)- A9% (4)
- B16% (7)
- C71% (32)
- D4% (2)
Explanation
The WatchKey take() method retrieves and removes next watch key, waiting if none are yet Note: A watch service that watches registered objects for changes and events. For example a file manager may use a watch service to monitor a directory for changes so that it can update its display of the list of files when files are created or deleted. A Watchable object is registered with a watch service by invoking its register method, returning a WatchKey to represent the registration. When an event for an object is detected the key is signalled, and if not currently signalled, it is queued to the watch service so that it can be retrieved by consumers that invoke the poll or take methods to retrieve keys and process events. Once the events have been processed the consumer invokes the key's reset method to reset the key which allows the key to be signalled and re-queued with further events.
Topics
Community Discussion
No community discussion yet for this question.