I need to have a Map which is thread safe and can have multiple values. I did write one using MultiMap as
private MultiMap<String, String> uploadIdETagMap = new MultiValueMap<String, String>();
//Function to get tag value and add to map to that uploadId key
public void uploadPartForMultiPartUpload() {
try {
UploadPartRequest partRequest = new UploadPartRequest();
partRequest = partRequest.withBucketName(bucketName).withInputStream(inputStream).withKey(fileName)
.withPartNumber(partNumber).withUploadId(uploadId).withPartSize(sizeOfData)
.withLastPart(isLastPart);
UploadPartResult result = s3Client.uploadPart(partRequest);
uploadIdETagMap.put(uploadId, result.getPartETag());
} catch (Exception e) {
log.error("Error uploading part: {} in multi part upload.", partNumber, e);
}
}
List<String> tagList = (List<String>) uploadIdETagMap.get(uploadId);
So everytime i will get new tag value for a particular uplaodId key and i need all of those tags at the end and there will be other uploads processing same time.
In the above code, tag gets added every time as the value of the MultiMap for specific uploadId key.
The above code works, but both MultiMap and MultiValueMap is deprecated and not thread safe.
So any suggestion how can i achieve this with latest version and thread safety.
