You can find a situation where a requirement prevents you from getting the locks in the same order in all the operations. In this situation, you can use the tryLock() method of the Lock class. This method returns a Boolean value to indicate whether you have control of the lock. You can try to get all the locks that you need to do the operation using the tryLock() method. If you can't get control of one of the locks, you must release all the locks that you may have had and start the operation again.