Ensure LockManager uses a consistent lock order

Backport of fix for JBTM-1350