To avoid data corruption in multithreaded Java programs, one has to protect the data that is shared between multiple threads as described in detail in CON30-J. Synchronize access to shared mutable variables. This can be done at the object level by using synchronized
blocks (coarse-grained locking), thus as a result locking out other threads from interfering. If synchronization is used judiciously, (See CON00-J. Use synchronization judiciously) deadlocks do not usually crop up.
...
This compliant solution avoids deadlocks because every thread requests monitors in the same order and thus as a result the locks are acquired (and released) correctly.
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
CON34- J | low | likely | high | P3 | L3 |
Automated Detection
TODO
...