This set of JUnit Multiple Choice Questions & Answers (MCQs) focuses on “Batching Tests”.
1. ________ submits a value-returning task for execution and returns a Future representing the pending results of the task.
a) submit(Callable<T> task)
b) awaitTermination
c) submit(Runnable task, T result)
d) invokeAll()
View Answer
Explanation: The Future’s get method will return the task’s result upon successful completion.
2. ____________ submits a Runnable task for execution and returns a Future representing that task.
a) submit(Callable<T> task)
b) awaitTermination
c) submit(Runnable task, T result)
d) invokeAll()
View Answer
Explanation: The function takes as parameters the task to submit and the result to return.
3. _____________ returns true if all tasks have completed following shut down.
a) submit(Callable<T> task)
b) isTerminated
c) submit(Runnable task, T result)
d) invokeAll()
View Answer
Explanation: isTerminated is never true unless either shutdown or shutdownNow was called first.
4. _____________ returns true if this executor has been shut down.
a) isShutdown
b) isTerminated
c) submit(Runnable task, T result)
d) invokeAll()
View Answer
Explanation: The isShutdown() method is used to check whether the executor has been shut down.
5. _______________ is used for the execution of the given tasks, returning a list of Futures holding their status and results after completion.
a) isShutdown
b) isTerminated
c) invokeAll(Collection<? extends Callable<T>> tasks)
d) invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
View Answer
Explanation: Future.isDone() is true for each element of the returned list.
6. ______________ executes the given tasks, returning the result of one that has completed successfully.
a) isShutdown
b) invokeAny(Collection<? extends Callable<T>> tasks)
c) invokeAll(Collection<? extends Callable<T>> tasks)
d) invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
View Answer
Explanation: Upon normal or exceptional return, tasks that have not completed are cancelled.
7. _____________ exception is thrown while invokeAll() is interrupted while waiting.
a) InterruptedException
b) NullPointerException
c) RejectedExecutionException
d) ArrayIndexOutOfBoundsException
View Answer
Explanation: If the exception is thrown, the unfinished tasks are cancelled.
8. NullPointerException is thrown if tasks or any of its elements are null.
a) True
b) False
View Answer
Explanation: If any of the tasks or elements are null, the methods throws a NullPointerException.
9. InterruptedException is thrown if any task cannot be scheduled for execution.
a) True
b) False
View Answer
Explanation: RejectedExecutionException is thrown if any task cannot be scheduled for execution.
10. ________________ initiates an orderly shutdown in which previously submitted tasks are executed.
a) Shutdown
b) invokeAny(Collection<? extends Callable<T>> tasks)
c) invokeAll(Collection<? extends Callable<T>> tasks)
d) invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
View Answer
Explanation: No new tasks will be accepted after calling Shutdown().
Sanfoundry Global Education & Learning Series – JUnit.
To practice all areas of Junit, here is complete set of 1000+ Multiple Choice Questions and Answers.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]
- Apply for Computer Science Internship
- Practice Programming MCQs
- Check Programming Books
- Check JUnit Books