Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Dive into the depths of Java with our quiz based on "Thinking in Java, Fourth Edition" by Bruce Eckel. Test your knowledge, solidify concepts, and prepare for certification with challenging questions and insightful feedback.

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


Which ExecutorService method is used to arrange asynchronous execution of a task?

  1. execute(Runnable task)

  2. start(Runnable task)

  3. run(Runnable task)

  4. dispatch(Runnable task)

The correct answer is: execute(Runnable task)

The ExecutorService interface provides a way to execute code concurrently in a controlled manner. The execute(Runnable task) method is used to arrange asynchronous execution of a task, meaning that the task will be executed in a separate thread. This allows multiple tasks to be executed simultaneously, resulting in increased efficiency. The other options, start(Runnable task), run(Runnable task), and dispatch(Runnable task), are not methods of the ExecutorService interface and are therefore incorrect options. Start() is a method of the Thread class and is used to start a new thread, run() is a method of the Runnable interface and is used to specify the code to be executed by a thread, and dispatch() is a method of the Dispatcher interface and is used to dispatch requests to a queue. Thus, only execute(Runnable task) is the correct method to arrange asynchronous execution of a task.