AMQ-5265 - fix race condition for task