Skip to content
Preptima

Concurrency & Multithreading interview questions

The memory model, executors, locks, atomics, virtual threads, and diagnosing races and deadlocks.

4 questions in Java & Spring.

medium1

mediumConceptDesign

What problem do virtual threads actually solve, and when do they not help?

Virtual threads make blocking cheap by unmounting from their carrier OS thread whenever they block, so thread-per-request scales to hundreds of thousands of concurrent tasks. Finalised in JDK 21, they do nothing for CPU-bound work, and pooling them defeats their purpose.

5 minmid, senior, staff

hard3

hardCodingDesign

Implement a thread-safe pool of N connections with acquire, release and a timeout.

A thread-safe connection pool pairs a Semaphore of N permits, which bounds how many connections exist and gives acquire its timeout, with a queue of idle connections. Acquire returns a lease that releases exactly once from a finally block, and a broken connection is discarded without losing its permit.

6 minmid, senior
hardConceptCoding

What does volatile guarantee, and what does it not?

It guarantees visibility and ordering: a volatile write happens-before every later read of that field, so everything the writer did beforehand becomes visible to the reader. It guarantees nothing about atomicity, so an increment is still a race and a volatile reference says nothing about the object it points to.

5 minmid, senior, staff