Yes, you are right,  more action need to be done before adding stage->jobID value into the map, a stage always be executed in an activejob with higher priority, when adding stage->jobID value into the Map, check whether the stage value exists in the Map and the jobID. if stage value exists and jobID is lower than current jobID, no update, else update the stage->jobID value in the Map