Every 2–5-year concurrency question — executors, locks, CompletableFuture, concurrent collections, deadlocks and thread safety — in one-line form with links.
Published September 25, 2026
This page condenses every question from the 2 to 5 Years course in these areas into a single line: the question, linked to its full answer, and the one-sentence answer you should be able to give instantly. Read down the list and answer each question aloud before reading the line. Wherever you hesitate, follow the link and revise the full answer — interviewers at your level expect these basics to be fluent, and they often open with them before going deeper.
Synchronization, Locks & Deadlocks — Interview Questions — open the lesson
Runnable and extending Thread? — Implementing Runnable (or Callable) separates the task from the thread that runs it. Your class can still extend something else, and the same task can run on a raw thread, an ExecutorService or a virtual thread.AtomicLong/LongAdder, ConcurrentHashMap, BlockingQueue; Guard compound state…synchronized work? — Every Java object has an intrinsic monitor lock. Entering a synchronized block or method acquires the monitor of the lock object: this for instance methods; the Class object for static methods; the object you name for a block.synchronized method and a synchronized block? — A synchronized method locks this (or the class) for the whole method. A synchronized block locks only the critical section, on any object you choose.volatile, and what does it guarantee? — volatile guarantees visibility and ordering for a single variable. Every read sees the most recent write by any thread, and a volatile write happens-before subsequent reads, so writes made before it are also visible to a thread that reads the volatile.volatile replace synchronization? — Only for single, independent reads and writes: flags, and publishing an immutable reference. It can't make compound operations atomic: count++ (read, modify, write), check-then-act, or keeping two variables consistent.StampedLock write lock, a Semaphore(1) or a hand-rolled lock all behave…Thread.holdsLock(obj) tells you whether the current thread holds obj's monitor. It's useful in assertions (assert Thread.holdsLock(this);); For ReentrantLock, use isHeldByCurrentThread(), plus isLocked(), getHoldCount() and getQueueLength(); For other threads,…synchronized and ReentrantLock? — Compared side by side in the full answer (table) — know each row.synchronized block? — The monitor is released automatically as the exception propagates out of the block. The compiler generates an exception handler that runs monitorexit, so other threads aren't blocked forever.synchronized methods and blocks; Explicit locks: ReentrantLock, ReentrantReadWriteLock, StampedLock; volatile, for visibility; Atomic variables: AtomicInteger, AtomicReference, LongAdder (lock-free CAS); …Executors, ThreadLocal & Concurrent Collections — Interview Questions — open the lesson
ExecutorService, and what methods does it provide? — ExecutorService decouples task submission from thread management. You submit Runnable/Callable tasks, and it runs them on a managed pool of reusable threads, handles queuing, and controls the lifecycle. Its main methods: Submitting work: execute, submit,…ExecutorService for? (Follow-up: how do you size and shut down a pool?) — Sizing:; Shutdown: call shutdown(), then awaitTermination(timeout). If it times out, call shutdownNow(), and handle InterruptedException properly. In Spring, prefer a ThreadPoolTaskExecutor bean: Spring manages its lifecycle, and it supports graceful shutdown.executor.submit(() -> …) in place of anonymous Runnable classes; parallel streams; CompletableFuture pipelines…volatile and atomics, under the rules of the Java Memory Model (happens-before).Collections.synchronizedList/Map, Vector, Hashtable) wraps every method in one lock.Runnable and Callable? — Runnable.run() returns nothing, and can't throw checked exceptions. Callable<V>.call() returns a value, and can throw checked exceptions.thread.interrupt() only sets a flag, and wakes up blocking calls (sleep, wait, join, BlockingQueue.take), which then throw InterruptedException.ThreadLocal? — Storing per-thread context without passing it through every method: The current user or tenant, transaction or trace IDs. Spring's SecurityContextHolder, transaction synchronisation and logging's MDC all use ThreadLocal; Per-thread instances of non-thread-safe helpers…submit() and execute()? — execute(Runnable) (from Executor) runs a task and returns nothing. An exception thrown by the task goes to the thread's uncaught exception handler, and gets printed.RejectedExecutionHandler, and how can you customise it? — A ThreadPoolExecutor rejects a task when it's shut down, or when all threads are busy and the bounded queue is full. The handler decides what happens next. The built-in policies: AbortPolicy (the default): throws RejectedExecutionException; CallerRunsPolicy: runs the…ConcurrentHashMap work internally? — It's a table of bins, like HashMap. Reads are lock-free, using volatile reads of the table and the nodes. Writes use a CAS to insert into an empty bin, and otherwise lock only that bin's first node (synchronized), so writers to different bins don't block each other.jcmd <pid> Thread.print, the recommended way (jcmd <pid> Thread.dump_to_file -format=json file also includes virtual threads); jstack <pid>.; Send SIGQUIT (kill -3 <pid>, or Ctrl+\ in the console, Ctrl+Break on Windows), which prints to stdout; VisualVM or JMC; …kubectl exec <pod> -- jcmd 1 Thread.print > dump.txt (the Java process is usually PID 1 in its container), or call the secured Actuator threaddump endpoint.Q: How should I use this list in the last week before an interview? A: Do one pass per day. Cover the answer text, say your answer out loud, then check it. Mark every question you could not answer crisply, and spend your study time only on the marked ones by opening the linked full answer. By the third pass the marked list should be short.
Q: The interviewer asks one of these basics — should I give only the one-liner? A: Lead with the one-liner, then add one concrete detail or example from your own work. At this level the follow-up usually probes the mechanism behind the basic answer, so be ready to go one layer deeper using the key points in the full lesson.
Q: Some answers here were corrected compared with common prep sheets — why? A: Several widely shared answers are outdated or wrong (for example, Java version details, removed Spring APIs, or SQL queries that miss edge cases). The full lessons call these out under "Common trap" — reading those is the fastest way to stand out from candidates who memorised the same sheets.