Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Strong Java concurrency answers start by naming the shared state, the guarantee needed to protect it, and the mechanism that provides that guarantee. This guide moves from core terminology to the Java Memory Model, synchronization and task execution. The 40 questions are a practical study set, not a definitive or ranked list of questions asked in interviews.

Foundations: threads, tasks and coordination

1. What is the difference between concurrency and parallelism?

Concurrency means a program makes progress on multiple tasks during overlapping periods; parallelism means tasks execute at the same time. A concurrent program may interleave work on one processor without running tasks simultaneously. Whether parallel execution is possible depends on the available execution resources and runtime conditions.

2. Why use multiple threads, and when might they not help?

Multiple threads can let a program make progress on independent work or avoid leaving other work idle while one task waits. They also add coordination costs: threads that contend for shared state can block one another, and managing concurrent work can make code harder to reason about. Concurrency does not automatically make a workload faster.

3. What is the difference between a task, a thread and an executor?

A task describes work to perform. A Thread is an execution mechanism. An Executor accepts a task and separates its submission from the decision about how it runs. Keeping these roles distinct makes it easier to change task execution without rewriting the task itself.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

4. How do Runnable and Callable differ?

Both represent work. A Runnable has a run() method that returns no result. A Callable has a call() method that can return a result and throw an exception. When a result or task failure must be collected, a callable submitted through an appropriate executor is often a better fit.

5. What is the difference between calling start() and run() on a thread?

start() starts a thread so that its work can execute independently. Calling run() directly is an ordinary method call on the current thread; it does not start a new thread. Confusing the two can make code look concurrent while it is actually executing sequentially on the caller.

6. What does join() do?

Calling join() on a thread makes the calling thread wait for that thread to finish. Under the Java Language Specification (JLS), actions in a thread happen-before another thread successfully returns from a join() on it. Use a bounded wait or another explicit recovery plan when waiting indefinitely would leave the application stuck.

7. What does interruption mean in Java?

Interruption is a coordination signal that one thread can use to request that another stop or respond to cancellation. It is not a general-purpose force-stop operation: the code doing the work must respond appropriately. A good answer explains what the interrupted task should do, such as stop waiting, clean up, or exit, rather than treating interruption as automatic termination.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

8. What is a race condition?

A race condition occurs when a result depends on how concurrent operations interleave. A data race is a specific memory-model condition: two conflicting accesses to the same variable, at least one of them a write, are not ordered by happens-before. A race can violate an application invariant even when its individual operations appear simple.

Memory visibility, ordering and shared state

9. What does the Java Memory Model define?

The Java Memory Model (JMM) defines which observations of shared memory are permitted in a concurrent program. It does not require the implementation to execute every source statement in one simple global sequence. The JLS cautions: “The behavior of threads, particularly when not correctly synchronized, can be confusing and counterintuitive.” — Java Language Specification, Java SE 26, Chapter 17, “Threads and Locks.”

10. What is happens-before?

Happens-before is a relationship used to reason about ordering and visibility between actions. For example, the JLS specifies that an unlock of a monitor happens-before a subsequent lock of that same monitor; a write to a volatile field happens-before subsequent reads of that field; calling Thread.start() happens-before actions in the started thread; and a thread’s actions happen-before another thread successfully returns from joining it.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

11. What makes two accesses conflicting?

Two accesses conflict when they access the same variable and at least one is a write. Under the JLS definition, a data race exists when conflicting accesses are not ordered by happens-before. To analyze a suspected race, identify the variable, the reads and writes, and the synchronization relationship—or lack of one—between those actions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

12. Does correct synchronization make a program logically correct?

No. The JLS describes conditions under which correctly synchronized executions appear sequentially consistent: their actions can be understood as occurring in a sequentially consistent order. That does not prove the program’s algorithm preserves its higher-level invariants. Synchronization can make state visible and exclude competing updates while the program still applies the wrong rule.

13. What does synchronized guarantee?

A synchronized block or method uses a monitor to provide mutual exclusion for code synchronized on that same monitor. Monitor release also has a visibility and ordering effect: an unlock happens-before a subsequent lock on the same monitor. To explain why synchronization is needed, name the invariant protected by the critical section, not just the keyword.

14. What is the difference between a synchronized instance method and a static method?

A synchronized instance method coordinates through the monitor associated with that object. A synchronized static method coordinates through the monitor associated with the class. Those are different monitors, so synchronizing an instance method does not by itself exclude a synchronized static method on the same class.

15. What does it mean that intrinsic locks are reentrant?

A thread that already holds an intrinsic monitor can acquire that same monitor again. This matters when synchronized code calls another method that synchronizes on the same object: the call does not deadlock merely because the thread already owns the monitor. Reentrancy does not remove the need to protect the right state or to consider other locks the code may acquire.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

16. What is the difference between visibility and atomicity?

Visibility concerns whether one thread can observe another thread’s write. Atomicity concerns whether an operation takes effect as one indivisible unit. A mechanism that establishes visibility does not necessarily make a multi-step operation indivisible; choose the coordination strategy based on the whole invariant that must be maintained.

volatile, locks and thread-safe design

17. What does volatile guarantee?

A write to a volatile field happens-before subsequent reads of that field, according to the JLS. This gives the field a synchronization role for visibility and ordering. It does not make every operation involving the field atomic.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

18. Why does volatile not make a counter increment safe?

An increment is a compound operation: read the current value, compute a new value, then write it. Two threads can read the same value before either writes, so one update can overwrite the other. Use an atomic operation or lock-based coordination when every increment must be counted.

19. When is a volatile field a reasonable choice?

It can suit a field used as a simple shared state flag when the required behavior is visibility and ordering for that field, rather than mutual exclusion across a multi-step invariant. Before choosing it, check every access and ask whether correctness depends on coordinating other state or on an indivisible update.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

20. When should you use synchronized instead of volatile?

Use synchronization when code must exclude competing threads while it checks or updates shared state as a unit. A volatile field is not a substitute for that mutual exclusion. Conversely, a lock is not automatically needed for a field whose design only requires the visibility and ordering provided by volatile access.

21. Why might a program use an explicit lock API instead of an intrinsic monitor?

Start by identifying a concrete requirement. Explicit lock APIs may be worth considering when the design needs a capability such as timed or interruptible lock acquisition, multiple conditions, or a particular fairness policy. Verify the exact behavior in the documentation for the Java version and class in use; do not claim a benefit merely because a lock API is more explicit.

22. What is a deadlock?

A deadlock occurs when threads wait indefinitely on dependencies that prevent one another from making progress. A simple lock-cycle example is thread A holding lock 1 while waiting for lock 2, while thread B holds lock 2 while waiting for lock 1. Describe the cycle or dependency to show why neither thread can proceed.

23. How can you reduce the risk of deadlock?

For a lock-based design, inspect where locks are acquired and what each thread may be waiting for. A consistent lock-acquisition order can prevent the two-lock cycle described above. Keep the dependency analysis specific to the design: reducing one cycle does not prove that every possible wait in a larger program is safe.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

24. What do starvation and livelock mean?

Starvation is a failure to make progress because a thread is repeatedly denied access to what it needs. In a livelock, threads remain active but keep responding to one another in a way that prevents useful progress. Both differ from deadlock, where the relevant threads are stuck waiting.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Executors, futures and task coordination

25. What is an Executor?

Executor separates task submission from the mechanism that carries out the task. That lets a caller express work without directly taking responsibility for how it is scheduled or run. The java.util.concurrent package documentation describes executors as a foundation for asynchronous task execution.

26. What does ExecutorService add?

ExecutorService extends the executor model with task execution and lifecycle management, including controlled shutdown. It is useful when code needs to submit work and then manage the service that owns its execution, rather than creating and managing a separate thread for every task.

27. What is a Future?

A Future represents the result of asynchronous computation. It provides operations to check completion, retrieve a result, or request cancellation. A future gives the caller a way to coordinate with submitted work, but cancellation should not be assumed to forcibly stop a task that does not respond to its cancellation signal.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

28. How should an executor be shut down?

Give the executor an explicit lifecycle: stop accepting new work when appropriate, decide how already-submitted work should be handled, and wait or otherwise coordinate with the tasks the application must finish. The exact shutdown methods and their behavior should be checked in the documentation for the Java version being used. Leaving executor ownership implicit makes it harder to know when the service and its tasks are done.

29. How do you size a thread pool?

There is no universal pool-size formula established by the Java concurrency API overview. Base the decision on the workload, the resources available, and the balance between useful work and contention or waiting. Explain what you would measure and why; do not present an unqualified thread count as correct for every machine or workload.

30. Why use an executor instead of creating a thread for every task?

With direct thread creation, the caller takes on thread management as well as task definition. Executor abstractions separate submission from execution and provide a service for coordinating task execution and shutdown; futures can represent results and cancellation. Choose based on the lifecycle and coordination the program needs, not on an assumption that an executor always makes the work faster.

31. How can a blocking queue help with producer-consumer work?

A blocking queue is a coordination structure that can support producers placing work for consumers to take. The java.util.concurrent documentation identifies blocking queues as useful for common producer-consumer and task-coordination designs. Pick a queue whose documented behavior matches whether the design needs bounded capacity, direct handoff, ordering, or delay semantics.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

32. How should you compare blocking queue choices?

Compare the actual contracts rather than treating all queues as interchangeable. Ask whether the application needs bounded capacity, direct handoff, a particular ordering, or delay behavior, then check the selected class’s official contract. Those properties affect how producers and consumers coordinate and what happens when work arrives faster than it is handled.

33. When should you use a concurrent collection?

Use one when multiple threads need to work with a shared collection and its documented concurrent behavior fits the operations the application performs. A concurrent collection does not automatically make a sequence of operations on it an atomic application-level transaction. Identify the invariant and check whether it spans more than the collection operation itself.

34. What should you consider before cancelling a task?

Cancellation is a request to coordinate a task’s end, not proof that the task has stopped. Identify how the running code will notice the request, what cleanup it must perform, and how the caller will determine completion. The Future abstraction provides a cancellation operation, but the task’s behavior still matters.

Explaining correctness in an interview

35. What does thread-safe mean?

Oracle’s concurrency overview describes a thread-safe function as one implemented so it can be executed by multiple concurrent threads. In an interview answer, go further: name the shared state and explain how the implementation preserves its invariants under concurrent use. The presence of a lock alone does not establish that the design is thread-safe.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

36. How do you decide whether to use an atomic operation or a lock?

First ask what must be indivisible. An atomic operation can fit a narrowly defined update; a lock can coordinate a larger critical section that protects related state. The right choice depends on the invariant and the operations that must be coordinated, not simply on which construct seems shorter.

37. How can immutable state help concurrent code?

If shared data cannot be changed after it is established, there are fewer competing writes to coordinate. Immutability is therefore a useful design consideration, but it does not by itself answer how the object becomes available to other threads or how related mutable state is protected. State those parts of the design separately.

38. How would you explain a shared-counter bug?

Show the operation as a read, a computation, and a write. If two threads can perform those steps concurrently, both may compute from the same old value and one update can be lost. Then name the guarantee the fix supplies: an indivisible update or mutual exclusion around the whole operation.

39. How do you reason about a visibility bug?

Trace the write and the read of the shared variable, then identify the happens-before relationship that orders them. For example, a volatile write orders with subsequent reads of that field, while unlocking and later locking the same monitor also establishes a happens-before relationship. If no relevant ordering exists, the reader cannot rely on ordinary single-thread intuition.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

40. What makes a strong answer to a concurrency question?

Use a short reasoning sequence: identify the shared state, state the invariant, name the needed guarantee—mutual exclusion, visibility, ordering, or atomicity—and explain how the chosen mechanism supplies it. Then mention a limitation or failure mode that matters to the example, such as an increment not being one atomic action or two threads waiting in a lock cycle.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.