Java Multithreading MCQ - Multiple Choice Questions And Answers
Q. What is multithreading in Java?
A. It refers to a technique in which a single thread is executed multiple times in a loop.B. It refers to a technique in which multiple threads are executed concurrently to improve performance.
C. It refers to a technique in which a thread is used to create multiple instances of a class.
D. It refers to a technique in which a thread is used to synchronize multiple objects.
Q. Which keyword is used to create a thread in Java?
A. newB. class
C. thread
D. start
Q. Which method is used to start a thread in Java?
A. run()B. start()
C. execute()
D. begin()
Q. What is the difference between Thread.sleep() and Object.wait() methods in Java?
A. Thread.sleep() is used to pause the execution of the current thread, while Object.wait() is used to suspend a thread until notified or interrupted.B. Thread.sleep() is used to suspend a thread until notified or interrupted, while Object.wait() is used to pause the execution of the current thread.
C. Thread.sleep() can only be called on the main thread, while Object.wait() can be called on any thread.
D. There is no difference between Thread.sleep() and Object.wait() methods.
Q. How can you prevent multiple threads from accessing a shared resource simultaneously in Java?
A. By using synchronized keywordB. By using volatile keyword
C. By using atomic variables
D. All of the above
Q. What is the purpose of the join() method in Java?
A. To pause the execution of the current threadB. To join two or more threads together
C. To wait for a thread to complete its execution
D. To terminate a thread
Q. What is deadlock in multithreading?
A. It occurs when two or more threads are waiting for each other to release resources and none of them can proceed.B. It occurs when a thread enters an infinite loop and never terminates.
C. It occurs when multiple threads try to access a shared resource simultaneously and cause data corruption.
D. It occurs when a thread calls the wait() method and waits indefinitely for a notify() or notifyAll() call.
Q. Which method is used to interrupt a thread in Java?
A. sleep()B. interrupt()
C. stop()
D. break()
Q. What is the purpose of the yield() method in Java?
A. To pause the execution of the current threadB. To make the current thread sleep for a specific duration
C. To transfer the CPU control to another thread of the same priority
D. To terminate the current thread
Q. What is the purpose of the isAlive() method in Java?
A. To check if a thread is currently runningB. To check if a thread is alive or dead
C. To check if a thread is in a sleep state
D. To check if a thread is waiting for a lock or monitor
Q. Which of the following is true about Java multithreading?
A.Java multithreading allows multiple threads to execute simultaneously on a single processor.B.
Java multithreading allows only one thread to execute at a time on a single processor.C.
Java multithreading is not supported in the Java programming language.D.
Java multithreading allows multiple threads to execute simultaneously on multiple processors.