Mastering Java Concurrency: ExecutorService & ForkJoinPool
Assess your understanding of Java concurrency using ExecutorService and ForkJoinPool.
Questions in this quiz
12 questions on Mastering Java Concurrency: ExecutorService & ForkJoinPool. Work through them here, then start the quiz to answer them and see your score.
1.What is the primary advantage of using ExecutorService over creating new threads manually?
- AIt allows for thread pooling and reuse.
- BIt provides built-in logging.
- CIt increases memory usage.
- DIt automatically handles exceptions.
2.Which method in ExecutorService is used to submit a Callable task?
- AinvokeAll()
- Bsubmit()
- Cexecute()
- Dshutdown()
3.How does ForkJoinPool differ from a regular ThreadPoolExecutor?
- AIt uses a work-stealing algorithm.
- BIt can only execute Runnable tasks.
- CIt does not support parallel execution.
- DIt requires more memory.
4.What is the purpose of the invokeAll() method in ExecutorService?
- ATo shutdown the ExecutorService.
- BTo execute tasks sequentially.
- CTo execute a collection of tasks and return a list of Futures.
- DTo execute a single task.
5.Which class should be extended to create a task for ForkJoinPool?
- AForkJoinTask
- BCallable
- CThread
- DRunnable
6.What happens if you call shutdown() on an ExecutorService?
- AIt waits for running tasks to finish before terminating.
- BIt restarts all tasks.
- CIt immediately stops all tasks.
- DIt throws an exception.
7.In ForkJoinPool, what is the purpose of the fork() method?
- ATo terminate a task.
- BTo combine results of subtasks.
- CTo split a task into subtasks.
- DTo start a new thread.
8.Which method in ExecutorService can be used to execute a task asynchronously?
- AawaitTermination()
- Bsubmit()
- CinvokeAny()
- Dexecute()
9.What does the join() method do in the context of ForkJoinPool?
- AIt waits for a task to complete and returns its result.
- BIt starts a new task.
- CIt cancels a task.
- DIt merges two tasks.
10.What is the effect of calling shutdownNow() on an ExecutorService?
- AIt restarts the ExecutorService.
- BIt waits for all tasks to complete.
- CIt stops all running tasks immediately.
- DIt cancels all pending tasks and attempts to stop running tasks.
11.How does the invokeAny() method in ExecutorService behave?
- AExecutes tasks in parallel and returns a list of results.
- BExecutes all tasks and returns the result of the first completed task.
- CExecutes tasks sequentially.
- DExecutes a single task and returns its result.
12.What is a common use case for ForkJoinPool in Java applications?
- AManaging database connections.
- BHandling I/O operations.
- CLogging application events.
- DPerforming recursive parallel computations.