1Z0-804 · Question #90
How many Threads are created when passing task to an Executor instance?
The correct answer is F. The method used to obtain the Executor determines how many Threads are used to execute tasks. The Executor interface provides a single method, execute, designed to be a drop-in replacementfor a common thread-creation idiom. If r is a Runnable object, and e is an Executor object you can replace(new Thread(r)).start(); with e.execute(r); However, the definition of execute…
Question
How many Threads are created when passing task to an Executor instance?
Options
- AA new Thread is used for each task.
- BA number of Threads equal to the number of CPUs Is used to execute tasks.
- CA single Thread Is used to execute all tasks.
- DA developer-defined number of Threads is used to execute tasks.
- EA number of Threads determined by system load is used to execute tasks.
- FThe method used to obtain the Executor determines how many Threads are used to execute tasks.
How the community answered
(18 responses)- A6% (1)
- C11% (2)
- D11% (2)
- F72% (13)
Explanation
The Executor interface provides a single method, execute, designed to be a drop-in replacementfor a common thread-creation idiom. If r is a Runnable object, and e is an Executor object you can replace(new Thread(r)).start(); with e.execute(r); However, the definition of execute is less specific. The low-level idiom creates a new thread and launches it immediately. Depending on the Executor implementation, execute may do the same thing, but is more likely to use an existing worker thread to run r, or to place r in a queue to wait for a worker thread to become available.
Topics
Community Discussion
No community discussion yet for this question.