Java Deadlocks prevented and detected