QuizzesJava Concurrency: Mastering Thread Pools & Executors
intermediate
java

Java Concurrency: Mastering Thread Pools & Executors

Assess your understanding of Java's thread pools and executor services.

18 minutes 12 questions Pass at 70%
Time Limit
18 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

12 questions on Java Concurrency: Mastering Thread Pools & Executors. Work through them here, then start the quiz to answer them and see your score.

  1. 1.What is the primary advantage of using a thread pool in Java?

    • AIt simplifies the syntax of multithreading.
    • BIt minimizes the overhead of thread creation and destruction.
    • CIt allows for dynamic thread creation.
    • DIt guarantees thread safety.
  2. 2.Which method is used to submit a task to an ExecutorService?

    • Asubmit()
    • Bexecute()
    • Crun()
    • Dinvoke()
  3. 3.What happens when a task is submitted to a fixed thread pool and all threads are busy?

    • AThe task is rejected.
    • BThe pool expands to accommodate the task.
    • CA new thread is created.
    • DThe task waits in a queue until a thread becomes available.
  4. 4.How can you gracefully shut down an ExecutorService?

    • ABy calling shutdown()
    • BBy calling shutdownNow()
    • CBy calling stop()
    • DBy calling terminate()
  5. 5.Which of the following is NOT a type of ExecutorService?

    • AScheduledThreadPool
    • BDynamicThreadPool
    • CCachedThreadPool
    • DSingleThreadExecutor
  6. 6.What is the difference between execute() and submit() methods in ExecutorService?

    • Asubmit() returns a Future, execute() does not.
    • Bsubmit() can throw exceptions, execute() cannot.
    • Cexecute() returns a Future, submit() does not.
    • Dexecute() can throw exceptions, submit() cannot.
  7. 7.What is the role of a Future object in Java concurrency?

    • AIt is used to create new threads.
    • BIt schedules tasks for execution.
    • CIt ensures thread safety.
    • DIt represents the result of an asynchronous computation.
  8. 8.Which method in the ExecutorService interface is used to schedule a task to run after a delay?

    • Adelay()
    • Bexecute()
    • Csubmit()
    • Dschedule()
  9. 9.How does a CachedThreadPool manage its threads?

    • AIt maintains a fixed number of threads.
    • BIt creates new threads as needed and reuses previously constructed threads when available.
    • CIt schedules threads to run at fixed intervals.
    • DIt creates a single thread to execute tasks.
  10. 10.Which method would you use to attempt to stop all actively executing tasks in an ExecutorService?

    • Acancel()
    • Bshutdown()
    • CshutdownNow()
    • Dterminate()
  11. 11.What is the purpose of the invokeAll() method in an ExecutorService?

    • ATo execute a collection of tasks and return a list of Futures.
    • BTo shut down the executor service.
    • CTo execute a single task and return its result.
    • DTo schedule tasks for repeated execution.
  12. 12.In a ScheduledThreadPoolExecutor, which method is used to execute a task repeatedly at fixed intervals?

    • Aexecute()
    • BscheduleAtFixedRate()
    • Csubmit()
    • DscheduleWithFixedDelay()