exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 74 discussion

Actual exam question from Oracle's 1z0-809
Question #: 74
Topic #: 1
[All 1z0-809 Questions]

Given the code fragment:
public class FileThread implements Runnable {
String fName;
public FileThread(String fName) { this.fName = fName; }
public void run () System.out.println(fName);}
public static void main (String[] args) throws IOException, InterruptedException {
ExecutorService executor = Executors.newCachedThreadPool();
Stream<Path> listOfFiles = Files.walk(Paths.get("Java Projects")); listOfFiles.forEach(line -> { executor.execute(new FileThread(line.getFileName().toString())); // line n1
});
executor.shutdown();
executor.awaitTermination(5, TimeUnit.DAYS); // line n2
}
}
The Java Projects directory exists and contains a list of files.
What is the result?

  • A. The program throws a runtime exception at line n2.
  • B. The program prints files names concurrently.
  • C. The program prints files names sequentially.
  • D. A compilation error occurs at line n1.
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Destroyer
Highly Voted 4 years, 7 months ago
Answer is B
upvoted 6 times
...
asdfjhfgjuaDCV
Most Recent 4 months, 3 weeks ago
B is the correct answer
upvoted 1 times
...
steefaand
5 months, 3 weeks ago
Selected Answer: B
B is answer.
upvoted 1 times
...
M_Jawad
4 years, 6 months ago
The walk method of the Files class can use depth-first to visit the path of the incoming file. The execute method of the ExecutorService object can use the new thread to execute the passed Runnable object. The shutdown method can close the ExecutorService object so that it no longer accepts new execution objects (Runnable or Callable), but does not wait for the currently executing and queued tasks to complete. The awaitTermination method can specify an upper limit time to wait for the ExecutorService object to finish processing all tasks. answer is B
upvoted 4 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago