From 03355a38beb5bf977aadf72d6cbd44aeb34ebe2b Mon Sep 17 00:00:00 2001 From: YangSen-qn Date: Thu, 7 Dec 2023 12:44:00 +0800 Subject: [PATCH] optimize some code --- .../android/storage/PartsUploadPerformerV1.java | 14 +++++++++----- .../android/storage/PartsUploadPerformerV2.java | 14 ++++++++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/library/src/main/java/com/qiniu/android/storage/PartsUploadPerformerV1.java b/library/src/main/java/com/qiniu/android/storage/PartsUploadPerformerV1.java index 90865567..ffc9b9aa 100644 --- a/library/src/main/java/com/qiniu/android/storage/PartsUploadPerformerV1.java +++ b/library/src/main/java/com/qiniu/android/storage/PartsUploadPerformerV1.java @@ -49,7 +49,7 @@ void uploadNextData(final PartsUploadPerformerDataCompleteHandler completeHandle UploadBlock block = null; UploadData chunk = null; - synchronized (this) { + synchronized (uploadSource) { try { block = info.nextUploadBlock(); chunk = info.nextUploadData(block); @@ -108,13 +108,17 @@ public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics reque } } if (responseInfo.isOK() && ctx != null && expiredAt != null) { - uploadBlock.ctx = ctx; - uploadBlock.expireAt = expiredAt; - uploadChunk.updateState(UploadData.State.Complete); + synchronized (uploadSource) { + uploadBlock.ctx = ctx; + uploadBlock.expireAt = expiredAt; + uploadChunk.updateState(UploadData.State.Complete); + } recordUploadInfo(); notifyProgress(false); } else { - uploadChunk.updateState(UploadData.State.WaitToUpload); + synchronized (uploadSource) { + uploadChunk.updateState(UploadData.State.WaitToUpload); + } } completeHandler.complete(false, responseInfo, requestMetrics, response); } diff --git a/library/src/main/java/com/qiniu/android/storage/PartsUploadPerformerV2.java b/library/src/main/java/com/qiniu/android/storage/PartsUploadPerformerV2.java index d968a4e2..a5dd84ed 100644 --- a/library/src/main/java/com/qiniu/android/storage/PartsUploadPerformerV2.java +++ b/library/src/main/java/com/qiniu/android/storage/PartsUploadPerformerV2.java @@ -13,6 +13,8 @@ import java.util.List; import java.util.Map; +import kotlin.jvm.Synchronized; + class PartsUploadPerformerV2 extends PartsUploadPerformer { PartsUploadPerformerV2(UploadSource uploadSource, @@ -79,7 +81,7 @@ void uploadNextData(final PartsUploadPerformerDataCompleteHandler completeHandle final UploadInfoV2 info = (UploadInfoV2) uploadInfo; UploadData data = null; - synchronized (this) { + synchronized (uploadSource) { try { data = info.nextUploadData(); if (data != null) { @@ -134,12 +136,16 @@ public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics reque } } if (responseInfo.isOK() && etag != null && md5 != null) { - uploadData.etag = etag; - uploadData.updateState(UploadData.State.Complete); + synchronized (uploadSource) { + uploadData.etag = etag; + uploadData.updateState(UploadData.State.Complete); + } recordUploadInfo(); notifyProgress(false); } else { - uploadData.updateState(UploadData.State.WaitToUpload); + synchronized (uploadSource) { + uploadData.updateState(UploadData.State.WaitToUpload); + } } completeHandler.complete(false, responseInfo, requestMetrics, response); }