Java multithreading interview questions test four things: the Java Memory Model (visibility and happens-before), safe sharing of state (synchronized, locks, atomics and concurrent collections), executors and CompletableFuture, and, since Java 21, virtual threads. Per openjdk.org, JDK 25 (general availability September 16, 2025) is the latest long-term-support release and JDK 27 (September 15, 2026) the newest feature release, as of November 17, 2026.
Below are 30 questions by level, five debugging scenarios and how interviews test this. Broader Java ground is in Java interview questions, and the functional APIs used with executors are in Java 8 interview questions.
Java multithreading interview questions: fundamentals (1–10)
- Process versus thread? A process has its own memory space; threads inside it share the heap but each has its own stack and program counter. Sharing the heap is what makes threads cheap and also what makes them dangerous.
- How do you create a thread? Extend
Thread, pass aRunnable, submit aCallableto anExecutorService, or start a virtual thread withThread.ofVirtual().start(task). In production code, prefer executors over raw threads. - start() versus run()?
start()creates a new thread that callsrun(). Callingrun()directly just executes it on the current thread. - What are the thread states?
NEW,RUNNABLE,BLOCKED(waiting for a monitor),WAITING,TIMED_WAITINGandTERMINATED, as inThread.State. - What does synchronized guarantee? Mutual exclusion on a monitor (the instance, the
Classfor static methods, or an explicit lock object) and visibility: releasing a monitor happens-before the next acquisition of it. It is reentrant. - What does volatile guarantee? Visibility and ordering for that variable: a write happens-before every later read of it. It does not make compound actions such as
count++atomic. - Why is count++ unsafe? It is read, add, write. Two threads can read the same value and both write the same result. Use
AtomicInteger.incrementAndGet(),synchronized, orLongAdderunder heavy contention. - wait() versus sleep()?
wait()must be called while holding the monitor, releases it and waits fornotify; call it in a loop that rechecks the condition, because of spurious wakeups.sleep()pauses without releasing any lock. - Runnable versus Callable?
Callablereturns a value and can throw checked exceptions; submitting it returns aFuture.Runnablereturns nothing. - How do interruption and join work?
interrupt()sets a flag; blocking calls such assleepthrowInterruptedExceptionand clear it. If you cannot handle it, restore it withThread.currentThread().interrupt().join()waits for a thread to finish.
Intermediate Java multithreading questions (11–20)
- What is happens-before? The Java Memory Model rule that decides what one thread must see of another's writes: program order, monitor unlock before lock, volatile write before read,
Thread.start()before the thread's actions, a thread's actions beforejoin()returns. Without such an edge there is no visibility guarantee. - How do you configure a ThreadPoolExecutor? Core size, maximum size, keep-alive, a work queue and a rejection policy. A bounded queue with
CallerRunsPolicyapplies backpressure;newCachedThreadPoolcan create unbounded threads. Since JDK 19,ExecutorServiceisAutoCloseable, so try-with-resources waits for tasks. - Future versus CompletableFuture?
Future.get()only blocks.CompletableFuturecomposes withthenApply,thenCompose,thenCombine,allOfandexceptionally. Its async methods default toForkJoinPool.commonPool(), so pass your own executor for blocking I/O. - ReentrantLock or synchronized?
ReentrantLockaddstryLockwith a timeout, interruptible locking, optional fairness and multipleConditions, but you mustunlock()infinally. Usesynchronizedwhen you do not need those. - ReadWriteLock and StampedLock? A
ReadWriteLockallows many readers or one writer.StampedLockadds optimistic reads that take no lock and are validated afterwards; it is not reentrant. - How is ConcurrentHashMap thread-safe? Since Java 8 it uses CAS and per-bin locking rather than one lock, rejects null keys and values, offers atomic
compute,mergeandputIfAbsent, and its iterators are weakly consistent.Collections.synchronizedMaplocks the whole map. - When is CopyOnWriteArrayList a good fit? Read-mostly lists such as event listeners: each write copies the array, so reads need no locking and iteration never throws
ConcurrentModificationException. - How do you implement producer-consumer? A
BlockingQueue: producersput(), consumerstake(), both blocking when full or empty.ArrayBlockingQueueis bounded, which gives natural backpressure. - CountDownLatch, CyclicBarrier or Semaphore? A latch is a one-shot countdown (wait for N events). A barrier is reusable and makes N threads wait for each other. A semaphore limits concurrent access with permits, for example to cap calls to a downstream service.
- What are ThreadLocal's risks? Values outlive requests in pooled threads, leaking memory or data between users, so always
remove()infinally. With millions of virtual threads, per-thread copies get expensive; scoped values, final in JDK 25 (JEP 506), share context safely.
Experienced and senior Java multithreading questions (21–30)
- What causes deadlock and how do you prevent it? Mutual exclusion, hold-and-wait, no preemption and circular wait. Prevent it with a global lock order,
tryLockwith timeouts, or fewer locks. Detect it in a thread dump (jstackorjcmd <pid> Thread.printreports Java-level deadlocks) or withThreadMXBean.findDeadlockedThreads(). - Livelock and starvation? Livelock: threads keep reacting to each other and make no progress, such as two retries backing off in step. Starvation: a thread never gets CPU or a lock because others always win; fair locks and bounded work help.
- What are virtual threads? Lightweight threads, final in JDK 21 (JEP 444), scheduled by the JVM onto a small pool of carrier threads. A virtual thread blocked on I/O unmounts and frees its carrier, so thread-per-request code scales to many concurrent tasks. They do not speed up CPU-bound work. Create one per task, for example with
Executors.newVirtualThreadPerTaskExecutor(), rather than pooling them. - What is pinning? A virtual thread that cannot unmount while blocked holds its carrier. On JDK 21 that happened inside
synchronized; JDK 24 (JEP 491) removed that case for most code, while native frames can still pin. On JDK 21, replacesynchronizedaround blocking I/O withReentrantLockand watch the JFRjdk.VirtualThreadPinnedevent. - What is structured concurrency? An API (
StructuredTaskScope) that treats related subtasks as one unit, so failure and cancellation propagate and no task leaks. It is still a preview feature: JDK 27 carries its seventh preview (JEP 533). - How does ForkJoinPool work? Each worker has a deque and steals tasks from others when idle, which suits recursive divide-and-conquer (
RecursiveTask). Parallel streams use the common pool, so blocking calls inside them starve everything else. - Why use LongAdder over AtomicLong? Under heavy contention many threads retry the same CAS.
LongAdderspreads increments across cells and sums them on read: faster writes, slightly costlier reads. - What is safe publication? Making a fully constructed object visible to other threads: through a
finalfield, avolatilefield, a lock, a concurrent collection or a static initializer. Immutable objects are thread-safe once safely published. - How do you write a thread-safe singleton? An enum singleton or the holder-class idiom, both relying on class initialization being thread-safe. Double-checked locking works only with a
volatilefield. - How do you size a thread pool? CPU-bound: about the number of cores (
Runtime.getRuntime().availableProcessors()). I/O-bound: cores multiplied by one plus the wait-to-compute ratio, then measure. With virtual threads, limit concurrency against the database or downstream service with a semaphore instead.
Java multithreading scenario and troubleshooting questions
The service hangs under load. Take three thread dumps a few seconds apart. Look for a reported deadlock, many threads BLOCKED on one monitor, or pool starvation: tasks waiting on other tasks submitted to the same full pool.
A metrics counter undercounts. A non-atomic ++ on a shared field. Switch to LongAdder or AtomicLong, and add a concurrent test that hammers it.
A worker loop never sees the stop flag. A visibility bug: the flag is a plain field. Make it volatile, use an AtomicBoolean, or stop the worker by interrupting it.
A CompletableFuture chain silently drops errors. Nothing handles the exceptional completion. Add exceptionally, handle or whenComplete, and remember join() wraps failures in CompletionException.
After moving to virtual threads, latency got worse. The bottleneck moved downstream: thousands of requests now queue for a small database connection pool. Cap concurrency with a semaphore, size the pool deliberately, and on JDK 21 check for pinning.
How Java multithreading interviews test this
| Format | What it usually looks like | How to prepare |
|---|---|---|
| Concept Q&A | synchronized versus volatile, happens-before, ConcurrentHashMap, executors | Explain each with a two-line example |
| Coding exercise | Producer-consumer, two threads printing odd and even numbers, a thread-safe cache or rate limiter | Write them with BlockingQueue, locks and atomics, out loud |
| Code review | "Is this class thread-safe?" | Look for shared mutable state, check-then-act and missing visibility |
| Senior design | Concurrency model for a high-traffic service; virtual threads versus reactive | Discuss backpressure, pool sizing and failure handling |
Spring services add their own threading questions, such as @Async executors; see Spring Boot interview questions. Design follow-ups are in OOP interview questions.
Where CoPilot Interview fits
CoPilot Interview is an AI interview assistant. Its free AI mock interview builds Java concurrency questions from your résumé and the job description, reads them aloud and scores each spoken answer out of 10, which is a fast way to find the answers above that you know but cannot yet explain cleanly under pressure. The browser demo has 145 practice questions in 10 tracks, scores typed answers out of 10 and needs no signup. The free plan gives 15 minutes a day of live help in sessions of up to 15 minutes, with AI mock interviews included. Paid plans are Standard at $24.99 a month and Pro at $39.99 a month, in the desktop app for Windows 10/11 and macOS 12 or later.
Use it to practice. Online assessments, proctored tests, take-home tasks with rules and AI-led rounds forbid outside help, so prepare for those instead of bringing a tool. For any live interview, follow your employer's rules.
Disclosure: CoPilot Interview is our product, so weigh what we say about it accordingly.
Frequently asked questions
What are the most asked Java multithreading interview questions?
synchronized versus volatile, happens-before, why count++ is unsafe, wait versus sleep, ExecutorService and thread pool configuration, ConcurrentHashMap internals, deadlock prevention, CompletableFuture and virtual threads.
What is the difference between synchronized and volatile?
synchronized gives mutual exclusion and visibility for a block of code; volatile gives visibility and ordering for one variable but no atomicity for compound updates.
Do virtual threads replace thread pools?
For blocking, I/O-bound tasks, mostly yes: create one virtual thread per task and limit concurrency with semaphores. CPU-bound work still belongs on a pool sized to the cores.
Which Java version should I prepare for?
An LTS release: JDK 21 introduced final virtual threads, and JDK 25 is the latest LTS as of November 17, 2026. Know that JDK 24 fixed synchronized pinning and that structured concurrency is still in preview.
How do I practice Java concurrency for interviews?
Write producer-consumer, odd-even printing and a bounded cache from scratch, break each one deliberately, read the thread dump, and explain the fix out loud.
Practice this interview before the real one
The AI mock interview builds questions from your resume and the job description, reads them aloud and scores each spoken answer out of 10. Included on the free plan.
Start a mock interview