ISPN-3773 State transfer thread can stop even though there are pending transfer tasks

https://issues.jboss.org/browse/ISPN-3773

Put the empty queue check and the thread stop in a synchronized block.
Simplify the state transfer loop by retrying failed tasks immediately.

No test for this, I think it would depend too much on the actual implementation.