Java Programming — Multithreading
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 71–80 of 100 questions in Multithreading
Q.71 Medium Multithreading
Which method is used to check the current state of a thread in Java?
A getStatus()
B getState()
C checkState()
D isAlive()
Correct Answer:  B. getState()
EXPLANATION

The getState() method returns the Thread.State enum indicating whether a thread is NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, or TERMINATED.

Take Test
Q.72 Medium Multithreading
What happens if you call interrupt() on a thread that is not in a waiting or sleeping state?
A The thread is immediately terminated
B An InterruptedException is thrown
C The interrupt status flag is set and the thread continues execution
D The method throws a RuntimeException
Correct Answer:  C. The interrupt status flag is set and the thread continues execution
EXPLANATION

interrupt() sets the interrupt status flag. If the thread is not waiting or sleeping, it continues execution but the status is marked as interrupted.

Take Test
Q.73 Medium Multithreading
Which of the following is a thread-safe collection in Java that can be used without explicit synchronization?
A ArrayList
B HashMap
C ConcurrentHashMap
D TreeMap
Correct Answer:  C. ConcurrentHashMap
EXPLANATION

ConcurrentHashMap is designed for concurrent access and is thread-safe. ArrayList, HashMap, and TreeMap require external synchronization for thread safety.

Take Test
Q.74 Easy Multithreading
What is the return type of the join() method in Java threading?
A Thread
B boolean
C void
D int
Correct Answer:  C. void
EXPLANATION

The join() method returns void. It causes the calling thread to wait until the thread on which it is called completes its execution.

Take Test
Q.75 Medium Multithreading
Consider a scenario where Thread A acquires Lock1 and tries to acquire Lock2, while Thread B acquires Lock2 and tries to acquire Lock1. What situation arises?
A Thread starvation
B Deadlock
C Livelock
D Race condition
Correct Answer:  B. Deadlock
EXPLANATION

When threads wait indefinitely for each other to release resources, it's a deadlock. This scenario is a classic deadlock example.

Take Test
Q.76 Easy Multithreading
Which exception is thrown when a thread is interrupted while waiting?
A ThreadException
B InterruptedException
C WaitException
D SleepException
Correct Answer:  B. InterruptedException
EXPLANATION

InterruptedException is thrown when a thread is interrupted during sleep(), wait(), or join() operations.

Take Test
Q.77 Medium Multithreading
What will be the output of the following code snippet?
java
class Test extends Thread {
public void run() {
System.out.print("T");
}
}
public class Main {
public static void main(String[] args) {
Test t = new Test();
t.run();
t.start();
}
}
A TT
B T
C Compilation error
D Runtime exception
Correct Answer:  A. TT
EXPLANATION

First t.run() executes directly (prints T), then t.start() creates a new thread and calls run() again (prints T). So output is TT.

Take Test
Q.78 Easy Multithreading
Which of the following statements about the notify() method is correct?
A It wakes up all waiting threads simultaneously
B It wakes up only one random waiting thread
C It terminates the current thread immediately
D It pauses the current thread indefinitely
Correct Answer:  B. It wakes up only one random waiting thread
EXPLANATION

notify() wakes up a single arbitrary thread that is waiting on the same monitor. notifyAll() wakes up all waiting threads.

Take Test
Q.79 Easy Multithreading
What is the primary purpose of the synchronized keyword in Java?
A To increase thread execution speed
B To prevent race conditions by ensuring mutual exclusion
C To create new threads automatically
D To handle exceptions in multithreaded environments
Correct Answer:  B. To prevent race conditions by ensuring mutual exclusion
EXPLANATION

The synchronized keyword ensures that only one thread can execute a critical section at a time, preventing race conditions and data inconsistency.

Take Test
Q.80 Easy Multithreading
In Java multithreading, which method is used to pause the execution of a thread for a specified number of milliseconds without releasing locks?
A Thread.sleep()
B Thread.pause()
C Thread.halt()
D Thread.suspend()
Correct Answer:  A. Thread.sleep()
EXPLANATION

Thread.sleep() pauses thread execution for specified milliseconds while retaining all locks. pause(), halt(), and suspend() are not standard Java methods for this purpose.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips