Java Concurrency Interview

Testing concurrent code question 168 of 180 mid

What static analysis helps with concurrency?

The compiler says nothing about thread safety, but analysers catch a real subset. SpotBugs has a concurrency category: inconsistent synchronisation (a field synchronised on 90% of accesses), wait outside a loop, naked notify, a lock not released on every path, locking on a boxed value, double-checked locking without volatile. ErrorProne enforces @GuardedBy properly and flags a family of misuse patterns at compile time.

They cannot prove correctness and they produce false positives, so they belong as a warning gate rather than a build-breaker for existing code. Their real value is on new code, where they catch the mistake before it reaches review.

testing tooling

Quiz yourself on Testing concurrent code Suggest a correction