我想在我的多线程下载程序中计算当前百分比。但是有一个奇怪的问题。第二次下载时的lastDownloadSize必须是lastDown的write和lastDownloadSize之和。 例子
有我的代码
private long getDownloadSize() {
synchronized (this) {
final AtomicLong totalWriteCount = new AtomicLong(0);
final AtomicLong lastDownloadSize = new AtomicLong(0);
for (DownloadTask task : downloadTasks) {
final long writeCount = task.getWriteCount();
totalWriteCount.addAndGet(writeCount);
final long downloadSize = task.getPosition().getDownloadSize();
lastDownloadSize.addAndGet(downloadSize);
}
System.out.println("===== writeCount : " + totalWriteCount + "lastDownloadSize : " + lastDownloadSize);
return totalWriteCount.addAndGet(lastDownloadSize.get());
}
}