Learn. Practice. Feel prepared.
Java Multithreading Objective Questions and Answers - Set 3
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 3 of the series.
Practice Java Multithreading MCQs with Detailed Explanations
Answer at least 12 questions to submit and verify answers.
31 Which is true about synchronized static methods? Medium
Correct answer:
They lock on the class object
synchronized static methods lock on the Class object.
32 Which API helps combine results of multiple async computations? High
Correct answer:
CompletableFuture
CompletableFuture provides composable asynchronous pipelines.
33 Which condition can cause a race condition? Medium
Correct answer:
Shared mutable state without synchronization
Race conditions occur when multiple threads modify shared mutable state without proper synchronization.
34 What is the output? ExecutorService ex = Executors.newSingleThreadExecutor(); ex.submit(() -> System.out.print("A")); ex.submit(() -> System.out.print("B")); ex.shutdown(); Medium
Correct answer:
AB
Single-thread executor preserves task order, so output will be AB.
35 Which mechanism supports reusable synchronization barriers? Medium
Correct answer:
CyclicBarrier
CyclicBarrier can be reused after all parties reach the barrier.
36 Which API supports dynamic number of participants in synchronization? High
Correct answer:
Phaser
Phaser allows dynamic registration and deregistration of parties.
37 What is false sharing? High
Correct answer:
Cache line contention due to nearby variables
False sharing occurs when independent variables share the same cache line causing performance degradation.
38 Which is the safest way to stop a thread? Medium
Correct answer:
Using a volatile flag
Using a volatile flag and cooperative cancellation is the safest way to stop a thread.
39 What is the effect of calling shutdownNow()? Medium
Correct answer:
Attempts to interrupt running tasks and returns queued tasks
shutdownNow() attempts to interrupt running tasks and returns tasks that were queued but not started.
40 Which queue is used internally by LinkedBlockingQueue? High
Correct answer:
Linked nodes
LinkedBlockingQueue uses linked nodes internally.
41 Which problem does happens-before rule prevent? High
Correct answer:
Visibility and reordering issues
Happens-before ensures visibility and ordering guarantees between threads.
42 Which is true about CopyOnWriteArrayList? Medium
Correct answer:
Reads are fast and writes are expensive
CopyOnWriteArrayList is optimized for read-heavy scenarios; writes create a new copy.
43 What happens when a thread is BLOCKED? Medium
Correct answer:
Waiting to acquire a monitor lock
BLOCKED state means the thread is waiting to acquire a monitor lock.
44 Which concurrency utility supports both barrier and phased execution? High
Correct answer:
Phaser
Phaser supports phased execution and barrier-like synchronization.
45 Which is the best approach to avoid deadlocks? High
Correct answer:
Acquire locks in a consistent global order
Acquiring locks in a consistent global order is a proven strategy to avoid deadlocks.