...
Deadlock can happen when multiple threads each holds a lock the other needs and are waiting for each other to release the resource. One way to fix the problem is to avoid circular wait by locking the mutex in a predefined order.
CON12-J. Avoid deadlock by requesting and releasing locks in the same+order describes the deadlock solution for Java
...