This set of Java Multiple Choice Questions & Answers (MCQs) focuses on “Multithreading – 2”.
1. What requires less resources?
a) Thread
b) Process
c) Thread and Process
d) Neither Thread nor Process
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: Deadlock is java programming situation where one thread waits for an object lock that is acquired by other thread and vice-versa.
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
View Answer
Explanation: 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
View Answer
Explanation: 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)
View Answer
Explanation: 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
View Answer
Explanation: 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()
View Answer
Explanation: 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.
Sanfoundry Global Education & Learning Series – Java Programming Language.
To practice all areas of Java, here is complete set on 1000+ Multiple Choice Questions and Answers on Java.
- Practice Information Technology MCQs
- Check Programming Books
- Practice BCA MCQs
- Check Java Books
- Practice Programming MCQs