Problem Statement
Name two practical strategies to prevent deadlocks in Java code.
Explanation
One: Impose a strict global lock ordering and acquire locks in that order everywhere. Two: Use tryLock with timeout and back off if you can’t acquire all locks. Other options: minimize lock scope, prefer immutable data, or replace coarse locks with higher-level concurrency utilities.
Practice Sets
This question appears in the following practice sets:
