Java Concurrency: Understanding Thread Pools & Executors
Assess your knowledge of Java's concurrency features focusing on thread pools and executors.
Questions in this quiz
12 questions on Java Concurrency: Understanding Thread Pools & Executors. Work through them here, then start the quiz to answer them and see your score.
1.What is the primary advantage of using a thread pool in Java?
- AReduced context-switching overhead
- BEasier debugging
- CSimplified code syntax
- DImproved memory management
2.Which method is used to initiate an orderly shutdown of an ExecutorService?
- AshutdownNow()
- Bterminate()
- Cshutdown()
- Dstop()
3.What happens if a task submitted to a fixed thread pool exceeds the pool's capacity?
- AThe task is rejected
- BThe pool size is increased
- CA new thread is created
- DThe task waits in a queue
4.Which ExecutorService method returns a Future object?
- AinvokeAny()
- Bexecute()
- Csubmit()
- DinvokeAll()
5.What is the default rejection policy for the ThreadPoolExecutor?
- ACallerRunsPolicy
- BAbortPolicy
- CDiscardOldestPolicy
- DDiscardPolicy
6.How can you create a single-threaded executor in Java?
- AExecutors.newScheduledThreadPool(1)
- BExecutors.newSingleThreadExecutor()
- CExecutors.newFixedThreadPool(1)
- DExecutors.newCachedThreadPool()
7.Which of the following is NOT a valid way to create a thread pool?
- AExecutors.newDynamicThreadPool()
- BExecutors.newScheduledThreadPool()
- CExecutors.newCachedThreadPool()
- DExecutors.newFixedThreadPool()
8.What is the purpose of the invokeAll() method in the ExecutorService?
- AExecutes multiple tasks and returns a list of Futures
- BExecutes a single task
- CExecutes tasks until one completes
- DExecutes tasks in parallel
9.Which class in Java provides a flexible thread pool implementation?
- AThread
- BRunnable
- CThreadPoolExecutor
- DExecutor
10.What is the behavior of the shutdownNow() method in ExecutorService?
- ARejects new tasks but continues executing existing ones
- BAttempts to stop all actively executing tasks
- CCompletes all tasks before shutting down
- DThrows an exception
11.In a ScheduledThreadPoolExecutor, what does the scheduleAtFixedRate() method do?
- ASchedules a task to execute repeatedly at a fixed rate
- BSchedules a task to execute once
- CSchedules a task to execute immediately
- DSchedules a task to execute at a fixed delay
12.What is the key difference between newCachedThreadPool() and newFixedThreadPool()?
- AnewCachedThreadPool() reuses idle threads
- BnewFixedThreadPool() creates threads on demand
- CnewFixedThreadPool() has no thread limit
- DnewCachedThreadPool() creates a fixed number of threads