Java Questions & Answers – Multithreading – 2

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

Answer: a
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

Answer: b
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

Answer: d
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.
advertisement
advertisement

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

Answer: b
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

Answer: a
Explanation: Deadlock is java programming situation where one thread waits for an object lock that is acquired by other thread and vice-versa.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

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

Answer: c
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

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

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

Answer: a
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

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

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

Answer: c
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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.