[JENKINS-24763] Prevent thread starvation by skipping old data removal onSave/remove if doDiscard is running.

Previous code for this purpose did this check after obtaining the synchronization lock, which is pointless. Also, previous flag was not thread safe.