Advanced Java: Mastering Thread Pools and Executor Service
Deep dive into Java's thread pools and executor service for efficient concurrency management.
Questions in this quiz
10 questions on Advanced Java: Mastering Thread Pools and Executor Service. Work through them here, then start the quiz to answer them and see your score.
1.What is the primary advantage of using a CachedThreadPool in Java's Executor framework?
- AIt provides a single-threaded executor.
- BIt creates new threads as needed and reuses idle threads.
- CIt maintains a fixed number of threads.
- DIt schedules tasks to run at a fixed rate.
2.In a FixedThreadPool, what happens when all threads are busy and a new task is submitted?
- AThe task is queued until a thread becomes available.
- BThe task is rejected.
- CA new thread is created to handle the task.
- DThe pool size is automatically increased.
3.Which method in the ExecutorService interface is used to shut down the executor immediately?
- AshutdownNow()
- Bshutdown()
- CawaitTermination()
- Dterminate()
4.What is the purpose of the Future interface in Java's concurrency framework?
- ATo synchronize thread execution.
- BTo handle exceptions in threads.
- CTo manage thread lifecycle.
- DTo represent the result of an asynchronous computation.
5.How does a ScheduledThreadPoolExecutor differ from a FixedThreadPool?
- AIt has a dynamic number of threads.
- BIt never reuses threads.
- CIt is single-threaded.
- DIt can schedule commands to run after a delay or periodically.
6.What is the default rejection policy for a ThreadPoolExecutor when a task cannot be accepted?
- ADiscardOldestPolicy
- BCallerRunsPolicy
- CDiscardPolicy
- DAbortPolicy
7.Which of the following is true about the ForkJoinPool in Java?
- AIt is used for IO-bound tasks.
- BIt only supports single-threaded execution.
- CIt is a type of CachedThreadPool.
- DIt is designed for work-stealing algorithms.
8.What is the role of the Callable interface in Java's concurrency framework?
- ATo execute tasks without returning a result.
- BTo manage thread priorities.
- CTo synchronize thread execution.
- DTo execute tasks with a return value and possible exception.
9.In Java's concurrency framework, what is the primary use of the Executors utility class?
- ATo manage thread priorities.
- BTo provide thread-safe data structures.
- CTo create instances of Executor, ExecutorService, and ScheduledExecutorService.
- DTo handle thread synchronization.
10.What is a potential drawback of using a single-threaded executor?
- ATasks can block indefinitely if one task takes too long.
- BIt consumes too many system resources.
- CTasks are executed concurrently.
- DIt cannot execute tasks periodically.