Fix possible deadlocks detected by Findbugs