Skip to content

Commit f8df993

Browse files
committed
Update README.md
1 parent 0522489 commit f8df993

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

docs/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@ class ResumableIO {
130130

131131
失败状况
132132
```java
133+
final int PERSIST_PACE = 5;
133134
final PutExtra extra = new PutExtra();
134135
final String key = "key";
135136
final String filepath = "xx/xx/xx";
136137
// 准备上传
137138
db.execute("INSERT INTO `table_resumable_table` (`key`, `filepath`) VALUES ('" + key + "', '" + filepath + "')");
138139
ResumableIO.put(key, InputStreamAt.fromFile(new File(filepath)), extra, new JSONObjectRet() {
139140
int process;
141+
int lastPersistProcess = 0;
140142
private void persist() {
141143
// 持久化
142144
db.execute("UPDATE `table_resumable_table` SET extra='" + extra.toJSON() + "', process=" + process + " WHERE `key`='" + key + "' and `filepath`='" + filepath + "'");
@@ -146,12 +148,12 @@ ResumableIO.put(key, InputStreamAt.fromFile(new File(filepath)), extra, new JSON
146148
db.execute("DELETE FROM `table_resumable_table` WHERE `key`='" + key + "' and `filepath`='" + filepath + "'");
147149
}
148150
public void onProcess(int current, int total) {
149-
int newProcess = current*100/total;
151+
process = current*100/total;
150152
// 每5%持久化一次
151-
if (newProcess % 5 == 0 && newProcess - process > 1) {
153+
if (process - lastPersistProcess > PERSIST_PACE) {
152154
persist();
155+
lastPersistProcess = process;
153156
}
154-
process = newProcess;
155157
}
156158
public void onFailure(Exception ex) {
157159
// 忽略处理exception,

0 commit comments

Comments
 (0)