Use ConcurrentHashMap#computeIfAbsent
in JarCacheSupport
#713
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While reading this code recently, I found some complicated logic to deal with a risk of multiple downloads of the same JAR getting scheduled, leading to special code to handle this race condition whose correctness is being challenged in #709. This complicated logic is not necessary if one instead uses
ConcurrentHashMap#computeIfAbsent
, whose Javadoc states:Due to these exactly once semantics, we don't have to worry about a race condition, so we can simplify the logic considerably, deleting the logic that is being challenged in the other PR rather than attempting to fix it. We also don't need the retry logic to deal with the executor rejecting the queue submission because (as an existing comment already notes)
AtmostOneThreadExecutor
never rejects submissions anyway (and any feasible replacement we might choose in the future would likely block rather than rejecting submissions).Testing done
Ran
mvn clean verify
as well as running a job on an inbound agent with the Git plugin to load a lot of classes. Verified that the JAR cache was correctly populated after being purged.