100 Java multithreading interview questions



 Here are 100 Java multithreading & concurrency interview questions, organized by level:


Beginner (30 Questions)

  1. What’s the difference between a process and a thread?

  2. How do you create a thread in Java (at least two ways)?

  3. What is the Runnable interface, and how does it differ from extending Thread?

  4. What is the Thread lifecycle? Name its states.

  5. How do you start a thread, and what happens if you call run() instead of start()?

  6. What does Thread.sleep() do, and how does it differ from Object.wait()?

  7. How do you make one thread wait for another to finish?

  8. What is the purpose of Thread.yield()?

  9. What is a daemon thread, and how do you create one?

  10. How do you set and get a thread’s priority, and does it guarantee order?

  11. What happens if a thread throws an unchecked exception and it’s not caught?

  12. How do you handle uncaught exceptions on a per-thread basis?

  13. What is synchronization, and when should you use the synchronized keyword?

  14. How do synchronized methods differ from synchronized blocks?

  15. What is an intrinsic lock (monitor) in Java?

  16. What is reentrant synchronization?

  17. How does Java prevent two threads from executing synchronized code on the same object?

  18. What’s the difference between a class-level and instance-level lock?

  19. What is the volatile keyword, and when is it needed?

  20. How does Java’s memory model ensure visibility of shared variables?

  21. What is thread safety, and how do you achieve it?

  22. How do you declare and use a ThreadLocal variable?

  23. What is deadlock, and what are its necessary conditions?

  24. How can you detect or avoid deadlock?

  25. What is livelock and how does it differ from deadlock?

  26. What is starvation in multithreading?

  27. How do wait(), notify(), and notifyAll() work?

  28. Why must wait()/notify() be called from a synchronized context?

  29. What is spurious wakeup, and how do you guard against it?

  30. How do you implement a simple producer–consumer using wait()/notify()?


Intermediate (40 Questions)

  1. What are the advantages of using the java.util.concurrent package over low-level primitives?

  2. How do you create and configure a ThreadPoolExecutor?

  3. What are the different executor interfaces and implementations (Executor, ExecutorService, ScheduledExecutorService)?

  4. How does Executors.newFixedThreadPool() differ from newCachedThreadPool()?

  5. What is a work queue in a thread pool, and which types exist?

  6. Explain the RejectionPolicy options in ThreadPoolExecutor.

  7. How do you shut down an executor gracefully vs. immediately?

  8. What is a Future, and how do you retrieve its result?

  9. How do you cancel a running task via its Future?

  10. What is a Callable, and how does it differ from Runnable?

  11. What are CountDownLatch, CyclicBarrier, and Semaphore, and when would you use each?

  12. How does Exchanger work? Give a use-case.

  13. What is a Phaser, and how does it differ from CyclicBarrier?

  14. What is ReadWriteLock, and why use it over a simple lock?

  15. How does ReentrantLock differ from synchronized?

  16. What is a fair lock vs. unfair lock?

  17. How do you use Condition objects with a ReentrantLock?

  18. What is StampledLock, and when is it useful?

  19. How do atomic classes (AtomicInteger, AtomicReference, etc.) work under the hood?

  20. Explain compare-and-set (CAS) and how it enables lock-free algorithms.

  21. What is ABA problem, and how do you mitigate it?

  22. How do you build a thread-safe non-blocking stack or queue?

  23. What is BlockingQueue, and name its implementations (ArrayBlockingQueue, LinkedBlockingQueue, etc.).

  24. How does PriorityBlockingQueue order its elements?

  25. What is transfer queue (LinkedTransferQueue)?

  26. How does Fork/Join framework work, and when would you use it?

  27. What is a RecursiveAction vs. RecursiveTask?

  28. How do you tune the ForkJoinPool’s parallelism level?

  29. What is work-stealing, and how does the Fork/Join pool implement it?

  30. How do you handle exceptions inside Fork/Join tasks?

  31. What are parallel streams, and how do they relate to the Fork/Join pool?

  32. What pitfalls should you watch for when using parallel streams?

  33. Explain the happens-before rules in the Java Memory Model.

  34. How do volatile variables establish a happens-before relationship?

  35. What is safe publication, and how do you achieve it?

  36. How do immutable objects help in concurrent code?

  37. Explain double-checked locking and its pitfalls in Java.

  38. How does java.util.concurrent implement time-outs on locks or queues?

  39. What is spin-locking, and where might it be used?

  40. How can you profile or debug thread contention in a running application?


Advanced (30 Questions)

  1. How would you design a high-throughput, low-latency concurrent system in Java?

  2. What are non-blocking algorithms (e.g., Michael-Scott queue) and how would you implement one?

  3. Explain disruptor pattern and its benefits.

  4. How do you implement lock striping for higher concurrency?

  5. What is false sharing, and how can you avoid it?

  6. How do you manage backpressure between producers and consumers in high-load scenarios?

  7. Explain reactive streams and how they relate to backpressure.

  8. How would you build a multi-level caching solution with concurrency in mind?

  9. What is thread affinity, and when is it useful?

  10. How can ThreadLocal lead to memory leaks in application servers?

  11. Describe structured concurrency (Project Loom) and its advantages.

  12. How do virtual threads (Fibers) change the concurrency model?

  13. What are continuations, and how might they be exposed in future Java versions?

  14. How do you safely interact with native code (JNI) from multiple threads?

  15. How can you optimize GC behavior in a highly concurrent application?

  16. Discuss the trade-offs between blocking and non-blocking designs.

  17. How would you implement a reliable messaging system with exactly-once delivery guarantees?

  18. What are transactional memory concepts, and are they available in Java?

  19. How do you design a parallel data processing pipeline with custom partitioning and merging?

  20. What is the role of ThreadGroup, and is it still relevant?

  21. How can VarHandles provide better performance or flexibility than atomic classes?

  22. How do you enforce ordering constraints in a concurrent workflow?

  23. What strategies exist for coordinating thousands of concurrent tasks with minimal overhead?

  24. How do you implement a high-performance publish/subscribe mechanism in Java?

  25. Explain lock-free snapshots or multi-version concurrency control (MVCC) in Java.

  26. How would you benchmark and stress-test a concurrent data structure?

  27. What is deterministic replay of multithreaded executions, and how might you achieve it?

  28. How would you prevent or diagnose heisenbugs in concurrent code?

  29. Discuss the future of Java concurrency beyond Loom—what features or improvements would you propose?

  30. Compare Java’s concurrency model with those of other platforms (e.g., Go, Erlang, .NET).


Use these to structure your study, mock interviews, and whiteboarding. Good luck!

Comments