Learn. Practice. Feel prepared.
Java Multithreading Objective Questions and Answers - Set 2
Test your skills in Java multithreading with carefully curated objective questions including output-based MCQs. Ideal for interview preparation and mastering concurrency concepts such as synchronization, executors, locks, atomic variables, deadlocks, and performance tuning. This is part 2 of the series.
Practice Java Multithreading MCQs with Detailed Explanations
Answer at least 12 questions to submit and verify answers.
16 What is a livelock? High
Correct answer:
Threads keep changing state but make no progress
In livelock, threads actively respond to each other but no progress is made.
17 Which method can interrupt a thread? Medium
Correct answer:
interrupt()
interrupt() sets the interrupt flag and can cause blocking calls to throw InterruptedException.
18 What is the effect of calling notify()? Medium
Correct answer:
One arbitrary waiting thread is woken up
notify() wakes up one waiting thread arbitrarily on that monitor.
19 Which is true about volatile writes? High
Correct answer:
They establish a happens-before relationship
volatile writes establish a happens-before relationship ensuring visibility to other threads.
20 What is the purpose of CountDownLatch? Medium
Correct answer:
Coordinate threads by waiting for a count to reach zero
CountDownLatch allows threads to wait until a set of operations complete.
21 Which is best for limiting concurrent access to a resource? Medium
Correct answer:
Semaphore
Semaphore controls the number of concurrent permits to access a resource.
22 What is a ForkJoinPool optimized for? High
Correct answer:
CPU-bound recursive divide-and-conquer tasks
ForkJoinPool is optimized for CPU-bound parallelism using work-stealing.
23 Which method submits a task and returns a Future? Medium
Correct answer:
submit()
submit() returns a Future representing the pending result.
24 What happens if two threads call join() on each other? High
Correct answer:
Deadlock
If two threads wait for each other using join(), a deadlock occurs.
25 Which collection is thread-safe without external synchronization? Medium
Correct answer:
CopyOnWriteArrayList
CopyOnWriteArrayList is thread-safe and optimized for read-heavy workloads.
26 Which problem is caused by instruction reordering? High
Correct answer:
Visibility issues
Instruction reordering can cause visibility and ordering issues in concurrent programs.
27 What is the default behavior of ReentrantLock? Medium
Correct answer:
Unfair locking
ReentrantLock is unfair by default for better throughput.
28 Which construct allows multiple readers but single writer? Medium
Correct answer:
ReadWriteLock
ReadWriteLock allows multiple concurrent readers but exclusive writers.
29 What is thread starvation? Medium
Correct answer:
Thread never gets CPU due to scheduling or locks
Starvation occurs when a thread is perpetually denied resources.
30 What is the output? int x = 0; Thread t1 = new Thread(() -> x++); Thread t2 = new Thread(() -> x++); t1.start(); t2.start(); Thread.sleep(100); System.out.println(x); High
Correct answer:
1 or 2
x++ is not atomic, so race conditions may result in 1 or 2 depending on timing.