This set of Java Quiz on “Multithreading”.
1. What requires less resources? Answer: a 2. What does not prevent JVM from terminating? Answer: b 3. What decides thread priority? Answer: d 4. What is true about time slicing? Answer: b 5. Deadlock is a situation when thread is waiting for other thread to release acquired object. Answer: a 6. What should not be done to avoid deadlock? Answer: c 7. What is true about threading? Answer: d 8. Which of the following is a correct constructor for thread? Answer: a 9. Which of the following stops execution of a thread? Answer: b 10. Which of the following will ensure the thread will be in running state? Answer: c Java for Quizzes, here is complete set on Multiple Choice Questions and Answers on Java.
a) Thread
b) Process
c) Thread and Process
d) Neither Thread nor Process
Clarification: Thread is a lightweight and requires less resources to create and exist in the process. Thread shares the process resources.
a) Process
b) Daemon Thread
c) User Thread
d) JVM Thread
Clarification: Daemon thread runs in the background and does not prevent JVM from terminating. Child of daemon thread is also daemon thread.
a) Process
b) Process scheduler
c) Thread
d) Thread scheduler
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.
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
Clarification: Time slicing is the process to divide the available CPU time to available runnable thread.
a) True
b) False
Clarification: Deadlock is java programming situation where one thread waits for an object lock that is acquired by other thread and vice-versa.
a) Avoid using multiple threads
b) Avoid hold several locks at once
c) Execute foreign code while holding a lock
d) Use interruptible locks
Clarification: To avoid deadlock situation in Java programming do not execute foreign code while holding a lock.
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
Clarification: start() eventually calls run() method. Start() method creates thread and calls the code written inside run method.
a) Thread(Runnable a, String str)
b) Thread(int priority)
c) Thread(Runnable a, int priority)
d) Thread(Runnable a, ThreadGroup t)
Clarification: Thread(Runnable a, String str) is a valid constructor for thread. Thread() is also a valid constructor.
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
Clarification: notify() wakes up a single thread which is waiting for this object.
a) yield()
b) notify()
c) wait()
d) Thread.killThread()
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.
