Home › Blog › Java Multithreading Interview Questions (2026): 30 Questions, From Threads to Virtual Threads

Java Multithreading Interview Questions (2026): 30 Questions, From Threads to Virtual Threads

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.

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)

  1. 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.
  2. How do you create a thread? Extend Thread, pass a Runnable, submit a Callable to an ExecutorService, or start a virtual thread with Thread.ofVirtual().start(task). In production code, prefer executors over raw threads.
  3. start() versus run()? start() creates a new thread that calls run(). Calling run() directly just executes it on the current thread.
  4. What are the thread states? NEW, RUNNABLE, BLOCKED (waiting for a monitor), WAITING, TIMED_WAITING and TERMINATED, as in Thread.State.
  5. What does synchronized guarantee? Mutual exclusion on a monitor (the instance, the Class for static methods, or an explicit lock object) and visibility: releasing a monitor happens-before the next acquisition of it. It is reentrant.
  6. 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.
  7. 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, or LongAdder under heavy contention.
  8. wait() versus sleep()? wait() must be called while holding the monitor, releases it and waits for notify; call it in a loop that rechecks the condition, because of spurious wakeups. sleep() pauses without releasing any lock.
  9. Runnable versus Callable? Callable returns a value and can throw checked exceptions; submitting it returns a Future. Runnable returns nothing.
  10. How do interruption and join work? interrupt() sets a flag; blocking calls such as sleep throw InterruptedException and clear it. If you cannot handle it, restore it with Thread.currentThread().interrupt(). join() waits for a thread to finish.

Intermediate Java multithreading questions (11–20)

  1. 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 before join() returns. Without such an edge there is no visibility guarantee.
  2. How do you configure a ThreadPoolExecutor? Core size, maximum size, keep-alive, a work queue and a rejection policy. A bounded queue with CallerRunsPolicy applies backpressure; newCachedThreadPool can create unbounded threads. Since JDK 19, ExecutorService is AutoCloseable, so try-with-resources waits for tasks.
  3. Future versus CompletableFuture? Future.get() only blocks. CompletableFuture composes with thenApply, thenCompose, thenCombine, allOf and exceptionally. Its async methods default to ForkJoinPool.commonPool(), so pass your own executor for blocking I/O.
  4. ReentrantLock or synchronized? ReentrantLock adds tryLock with a timeout, interruptible locking, optional fairness and multiple Conditions, but you must unlock() in finally. Use synchronized when you do not need those.
  5. ReadWriteLock and StampedLock? A ReadWriteLock allows many readers or one writer. StampedLock adds optimistic reads that take no lock and are validated afterwards; it is not reentrant.
  6. 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, merge and putIfAbsent, and its iterators are weakly consistent. Collections.synchronizedMap locks the whole map.
  7. 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.
  8. How do you implement producer-consumer? A BlockingQueue: producers put(), consumers take(), both blocking when full or empty. ArrayBlockingQueue is bounded, which gives natural backpressure.
  9. 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.
  10. What are ThreadLocal's risks? Values outlive requests in pooled threads, leaking memory or data between users, so always remove() in finally. 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)

  1. 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, tryLock with timeouts, or fewer locks. Detect it in a thread dump (jstack or jcmd <pid> Thread.print reports Java-level deadlocks) or with ThreadMXBean.findDeadlockedThreads().
  2. 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.
  3. 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.
  4. 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, replace synchronized around blocking I/O with ReentrantLock and watch the JFR jdk.VirtualThreadPinned event.
  5. 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).
  6. 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.
  7. Why use LongAdder over AtomicLong? Under heavy contention many threads retry the same CAS. LongAdder spreads increments across cells and sums them on read: faster writes, slightly costlier reads.
  8. What is safe publication? Making a fully constructed object visible to other threads: through a final field, a volatile field, a lock, a concurrent collection or a static initializer. Immutable objects are thread-safe once safely published.
  9. 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 volatile field.
  10. 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

FormatWhat it usually looks likeHow to prepare
Concept Q&Asynchronized versus volatile, happens-before, ConcurrentHashMap, executorsExplain each with a two-line example
Coding exerciseProducer-consumer, two threads printing odd and even numbers, a thread-safe cache or rate limiterWrite 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 designConcurrency model for a high-traffic service; virtual threads versus reactiveDiscuss 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