Change the order in which the rows are locked.
Right now you have some code that locks some tableA row(s), then some tableB row(s). While that is running, another process locks some tableB row(s), then some tableA row(s). When they are trying to lock the same rows, the deadlock occurs.
If all of the code is designed to lock tableA rows, then TableB rows, the deadlock will not happen. This sometimes means locking a row before it is actually needed by the code.
If there is reluctance to change the code, it becomes a scheduling problem. The tasks that deadlock should not be run concurrently.
Hope this helps,