250+ TOP MCQs on Multithreading and Answers

This set of Java Quiz on “Multithreading”.

1. What requires less resources?
a) Thread
b) Process
c) Thread and Process
d) Neither Thread nor Process

Answer: a
Clarification: Thread is a lightweight and requires less resources to create and exist in the process. Thread shares the process resources.

2. What does not prevent JVM from terminating?
a) Process
b) Daemon Thread
c) User Thread
d) JVM Thread

Answer: b
Clarification: Daemon thread runs in the background and does not prevent JVM from terminating. Child of daemon thread is also daemon thread.

3. What decides thread priority?
a) Process
b) Process scheduler
c) Thread
d) Thread scheduler

Answer: d
Clarification: Thread scheduler decides the priority of the thread execution. This cannot guarantee that higher priority thread will be executed first, it depends on thread scheduler implementation that is OS dependent.

4. What is true about time slicing?
a) Time slicing is OS service that allocates CPU time to available runnable thread
b) Time slicing is the process to divide the available CPU time to available runnable thread
c) Time slicing depends on its implementation in OS
d) Time slicing allocates more resources to thread

Answer: b
Clarification: Time slicing is the process to divide the available CPU time to available runnable thread.

5. Deadlock is a situation when thread is waiting for other thread to release acquired object.
a) True
b) False

Answer: a
Clarification: Deadlock is java programming situation where one thread waits for an object lock that is acquired by other thread and vice-versa.

  250+ TOP MCQs on Try & Catch and Answers

6. What should not be done to avoid deadlock?
a) Avoid using multiple threads
b) Avoid hold several locks at once
c) Execute foreign code while holding a lock
d) Use interruptible locks

Answer: c
Clarification: To avoid deadlock situation in Java programming do not execute foreign code while holding a lock.

7. What is true about threading?
a) run() method calls start() method and runs the code
b) run() method creates new thread
c) run() method can be called directly without start() method being called
d) start() method creates new thread and calls code written in run() method

Answer: d
Clarification: start() eventually calls run() method. Start() method creates thread and calls the code written inside run method.

8. Which of the following is a correct constructor for thread?
a) Thread(Runnable a, String str)
b) Thread(int priority)
c) Thread(Runnable a, int priority)
d) Thread(Runnable a, ThreadGroup t)

Answer: a
Clarification: Thread(Runnable a, String str) is a valid constructor for thread. Thread() is also a valid constructor.

9. Which of the following stops execution of a thread?
a) Calling SetPriority() method on a Thread object
b) Calling notify() method on an object
c) Calling wait() method on an object
d) Calling read() method on an InputStream object

Answer: b
Clarification: notify() wakes up a single thread which is waiting for this object.

10. Which of the following will ensure the thread will be in running state?
a) yield()
b) notify()
c) wait()
d) Thread.killThread()

Answer: c
Clarification: wait() always causes the current thread to go into the object’s wait pool. Hence, using this in a thread will keep it in running state.

  250+ TOP MCQs on Java.lang – Object & Math Class and Answers

Java for Quizzes, here is complete set on Multiple Choice Questions and Answers on Java.

contest

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top