Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Testing cannot prove the absence of concurrency bugs. As a senior technical leader, how would you set an organisation-wide strategy for concurrency correctness?

Since testing cannot prove that concurrency bugs are absent, the strategy has to make them rare by design and catch the rest through several independent layers. I would steer teams towards designs without shared mutable state, through immutability, thread confinement and message passing; standardise on high-level, well-tested library constructs and confine low-level concurrency code to a few reviewed modules; keep a small group of experienced reviewers for concurrency-sensitive changes; use stress tools such as jcstress for shared libraries and run tests on both x86 and ARM; and turn incidents into rules and static checks.

Background to this question

At organisational scale, concurrency bugs are a statistical certainty: hundreds of engineers, thousands of services and code paths, and a few people who deeply understand the Java memory model. The bugs that escape are expensive, because they are intermittent, data-corrupting and hard to diagnose. A leader cannot review every line, so the question is how to shape the environment so that most engineers rarely need to write tricky concurrent code, and the remaining risk is concentrated where experts can watch it. In this answer, we will recap why testing falls short, then build the strategy in layers: design principles, standard building blocks, expert review, specialised testing, and learning from incidents, with how to roll it out.

1Why Testing Alone Cannot Be the Strategy

A concurrency bug needs a particular interleaving of operations across threads, and the number of possible interleavings grows explosively with the number of threads and steps. A test samples a tiny fraction of them, influenced by the test machine's core count, load and CPU architecture. So a green test suite says that no bad interleaving happened in those runs, not that none exists. That means correctness has to come mostly from how the code is designed and reviewed, with testing as one safety net among several.

The practical goal is therefore twofold: reduce the amount of code where a concurrency bug is even possible, and make the remaining code visible, reviewed and stressed.

Step throughLayers of defence for concurrency correctness
  1. Design: avoid shared mutable stateimmutability, confinement, message passing
  2. Standard building blocksexecutors, concurrent collections, atomics, database constraints
  3. Low-level code in reviewed modules onlycustom locks and lock-free code in a few libraries
  4. Expert review for sensitive changesa small group, clear triggers
  5. Specialised testingjcstress, Lincheck, x86 and ARM, load tests
  6. Learning from incidentspatterns become rules and static checks

6 layers, from the top down. Step through them one at a time.

2Design Principles: Remove the Shared Mutable State

Every concurrency bug involves state that is shared between threads and changed by at least one of them. Remove either condition and the bug class disappears. Immutability removes the change: Java records, List.copyOf and Map.copyOf, and immutable value objects can be shared freely. Confinement removes the sharing: an object created and used within one request, one actor or one partition is only ever touched by one thread. Message passing replaces shared state with handing data over a queue or a Kafka topic, so each piece of state has a single owner.

In a typical Spring service this translates into simple, teachable rules: singleton beans hold no mutable request data; caches use proven libraries; shared state lives in the database, where constraints and transactions protect it; and work for the same entity goes to the same partition. These rules go into the engineering guidelines with examples, and they are the first thing design reviews check.

3Standard Building Blocks, and Where Low-Level Code May Live

Most engineers should never write wait and notify, volatile tricks or lock-free algorithms. The JDK and a few well-tested libraries provide what we need: ExecutorService and virtual threads, CompletableFuture and structured concurrency, ConcurrentHashMap and atomics, and for distributed state, database constraints, conditional updates and idempotency keys. I would publish a short list of approved constructs, with internal starter libraries that wrap common patterns such as idempotent consumers and rate limiters.

Low-level concurrency code is sometimes justified, for example in a high-performance shared library. The rule is that it lives in designated modules with named owners, documentation of the invariants, and extra testing. Static analysis can enforce the boundary, for example by flagging uses of Object.wait, Thread.stop, custom Unsafe or VarHandle access, or synchronized blocks containing I/O, outside those modules.

Default choices instead of hand-written concurrency
NeedStandard choiceAvoid by default
Run work in parallelExecutorService, virtual threadsnew Thread, wait and notify
Shared map or cacheConcurrentHashMap, a cache librarysynchronized HashMap, hand-made locks
Counter or flagAtomicLong, LongAddervolatile with ++
Coordinate tasksCompletableFuture, structured concurrencyCountDownLatch mazes
State across instancesDB constraint, conditional updatein-JVM locks

4Expert Review With Clear Triggers

Concurrency expertise is scarce, so we use it deliberately. A small group, perhaps five to eight engineers across the organisation, acts as reviewers for concurrency-sensitive changes. The triggers are concrete so teams know when to ask: new shared mutable state in a singleton, any code in the low-level modules, new lock usage on a request path, changes to transaction boundaries or isolation levels, and new distributed coordination. A code-owner rule on the low-level modules makes their review automatic there.

The group also teaches. Their review comments, a short internal course on the memory model and common patterns, and office hours spread the knowledge, so the number of people who can review grows over time instead of the group becoming a bottleneck.

5Specialised Testing Where It Pays Off

Testing still matters; it just has to be targeted. Shared libraries with low-level code get jcstress tests for their memory-model assumptions and Lincheck-style checks for their data structures. Services get stress tests for the specific invariants that matter, such as 'no duplicate shipment', and load tests at production concurrency for contention. Because x86 hides some reorderings that ARM exposes, and our production fleet increasingly runs on ARM, CI runs the concurrency-sensitive suites on both architectures. A bug that only fails on ARM is not hypothetical; it is exactly the kind that passes every test on a developer laptop for years.

6Learning From Incidents and Rolling It Out

Every concurrency incident is a free lesson. The review asks not only what broke but which layer should have stopped it: was the design allowed by our guidelines, should a reviewer have been triggered, could a static check have found it? Recurring shapes, such as check-then-act across instances or remote calls inside synchronized blocks, become checklist items and, where possible, automated rules in static analysis such as Error Prone or SpotBugs, or custom ArchUnit tests.

I would roll this out in stages: guidelines and the approved constructs list first, because they are cheap; then the reviewer group and code owners for low-level modules; then ARM in CI and jcstress for shared libraries; and the incident-to-rule loop from the start. We measure progress by the number of concurrency incidents per quarter and their time to diagnosis, and by how many issues the static checks and reviews catch before merge.

7Follow-up questions

How do you keep the expert reviewer group from becoming a bottleneck?

By keeping the triggers narrow so only truly sensitive changes need them, by making most code not need them at all through the approved constructs, and by growing the group through teaching, pairing and documented review guidance. If review wait times rise, that is a signal to train more reviewers or to provide a library that removes the need for the pattern being reviewed.

Why run tests on ARM specifically?

Because ARM's memory model is weaker than x86's, so reorderings that the Java memory model allows actually happen on ARM but almost never on x86. Code with a missing volatile or an unsafe publication may pass forever on x86 build agents and fail on ARM production servers. Running the concurrency-sensitive tests on both catches that class of bug before release.

Can static analysis really find concurrency bugs?

It finds certain shapes reliably: fields accessed both inside and outside synchronized blocks, non-thread-safe types in static fields, I/O inside synchronized, double-checked locking without volatile, and calls to deprecated thread methods. It cannot prove a design correct, but it removes many common mistakes cheaply, and encoding lessons from our own incidents makes it more valuable over time.

8Conclusion

In this answer, we accepted that testing cannot prove concurrency correctness and built a layered strategy instead: design principles that avoid shared mutable state through immutability, confinement and message passing; a standard set of high-level library constructs, with low-level code confined to reviewed modules; a small expert reviewer group with clear triggers that also teaches; targeted stress testing with jcstress and Lincheck on both x86 and ARM; and a loop that turns incident patterns into checklist items and static checks, rolled out in stages and measured by incidents and pre-merge catches.

What to say in the interviewAbout 90 seconds aloud

Open with

Since tests cannot prove the absence of concurrency bugs, my strategy would be to make them rare by design and to catch the rest with several independent layers.

Then, if they want more

The first layer is design: I would make it the default to avoid shared mutable state, using immutable values, confining state to one request or one partition, and passing messages instead of sharing objects, with simple rules like singleton beans hold no mutable request data and state across instances lives in the database behind constraints.

Second, standard building blocks: executors and virtual threads, CompletableFuture, ConcurrentHashMap and atomics, database conditional updates and idempotency keys, wrapped in internal libraries for common patterns. Low-level concurrency code, custom locks or lock-free structures, only lives in a few designated modules with owners.

Third, a small group of experienced reviewers with clear triggers, such as new shared state, lock usage on hot paths or changes to transaction boundaries, who also teach so the group grows.

Fourth, targeted testing: jcstress and Lincheck for shared libraries, invariant stress tests and production-like load tests for services, and running these suites on both x86 and ARM, because ARM exposes reorderings x86 hides. Fifth, every concurrency incident asks which layer should have caught it, and recurring patterns become checklist items and static checks.

I would roll it out in that order and track incidents per quarter and issues caught before merge.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Testing cannot prove the absence of concurrency bugs. As a senior technical leader, how...": https://scrivio-interview-library.netlify.app/java/concurrency-problems/bdf5c05d5e/