[KARAF-2812] Correct order of acquired locks to avoid possible deadlock