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

Put the empty queue check and the thread stop in a synchronized block.
Simplify the state transfer loop by retrying failed tasks immediately.