🧵 Java Concurrency — interview questions

12 questions. Filter by what the role asks for; open one for the six layers of the answer. The course is where the answers come from.

12 of 12

01What is the Java Memory Model, and what does happens-before guarantee?Memory modelhard3-5y02When would you use synchronized, and when volatile?Memory modelmedium0-2y03Why would you choose ReentrantLock over synchronized?Locksmedium3-5y04Explain ThreadPoolExecutor's parameters and how a task moves through them.Executorshard3-5y05thenApply vs thenCompose — and which thread runs the callback?Executorsmedium3-5y06How is ConcurrentHashMap different from Collections.synchronizedMap, and what is still not atomic?Collectionsmedium3-5y07What are virtual threads, and what changes when you enable them in a Spring service?Virtual threadshard5-8y08Production requests are hanging. How do you tell a deadlock from thread-pool exhaustion?Diagnosishard5-8y09How does AtomicInteger work without a lock, and when does LongAdder win?Locksmedium3-5y10How do you cancel a thread, and what must you do when you catch InterruptedException?Memory modelmedium0-2y11A service stops answering at 02:14, right after its rates provider returned a 503. CPU is idle, no errors are logged, and the thread dump shows no deadlock. Every request thread is `WAITING (parking)` on the same `ReentrantLock$NonfairSync`, and the scheduler thread that last called `refresh()` is alive and sleeping. What happened, how do you find the owner, and what are the two fixes?Lockshard8+y12A rates cache is `rates.computeIfAbsent(ccy, c -> rateClient.fetch(c))` on a `ConcurrentHashMap`. When the provider's 30 ms call becomes a 12-second call, requests for currencies that were already cached start timing out, but only for some currencies. Explain exactly which calls block and which do not, and fix it without adding a library.Collectionshard8+y