File tree Expand file tree Collapse file tree 2 files changed +4
-243
lines changed
app/src/main/java/com/obs/services/internal Expand file tree Collapse file tree 2 files changed +4
-243
lines changed Original file line number Diff line number Diff line change @@ -62,14 +62,18 @@ public void progressEnd() {
6262 protected void doProgressChanged (int bytes ) {
6363 long transferred = this .transferredBytes .addAndGet (bytes );
6464 long newlyTransferred = this .newlyTransferredBytes .addAndGet (bytes );
65+ // 获取当前时间戳,减去上次更新速度的时间,如若时间差大于 1000ms,则对上一秒传输字节数进行更新
6566 long now = System .currentTimeMillis ();
67+ // 采用局部变量保证线程安全
6668 long swapIntervalTime = now - lastSwapTimeStamp .get ();
6769 currentSecondBytes .addAndGet (bytes );
70+ // 上一秒传输字节设置为 当前传输字节 / 耗时,更新当前传输字节为 0,重设更新时间
6871 if (swapIntervalTime > 1000 ) {
6972 lastSecondBytes .set ((long ) (currentSecondBytes .get () / (swapIntervalTime / 1000.0 )));
7073 currentSecondBytes .set (0 );
7174 lastSwapTimeStamp .set (now );
7275 }
76+ // 当新传输字节数大于用户设置阈值时更新回调函数,其中瞬时速度使用上一秒传输字节数作为近似值
7377 if (newlyTransferred >= this .intervalBytes
7478 && (transferred < this .totalBytes || this .totalBytes == -1 )) {
7579 if (this .newlyTransferredBytes .compareAndSet (newlyTransferred , -newlyTransferred )) {
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments