Use a deadlock-avoidance strategy to avoid deadlock. The main method is not tested. Follow the example in the lessons. Only make changes in safeMethod.
Determining locking order
Implement the logic of the isLockOrderNormal method, which should determine: whether the order of the synchronized blocks in the someMethodWithSynchronizedBlocks method matches the order of the arguments passed to it. If o1 is synchronized first and then o2, the method should return true.
Eliminating deadlock using open calls
Synchronized methods that internally invoke the synchronized methods of other classes cause deadlock. 1. Move the synchronization from the method to the synchronized block, where you'll place only the necessary parts of the code. 2. Eliminate unnecessary method synchronization.