[JENKINS-22558] Avoid deadlocks by using RentrantLock#tryLock() instead of synchronized.