@@ -88,7 +88,17 @@ public FileDownloadDatabase getDatabaseInstance() {
88
88
synchronized (this ) {
89
89
if (database == null ) {
90
90
database = getDownloadMgrInitialParams ().createDatabase ();
91
- maintainDatabase (database .maintainer ());
91
+ // There is no reusable thread for this action and this action has
92
+ // a very low frequency, so, a new thread is simplest way to make this action
93
+ // run on background thread.
94
+ final String maintainThreadName =
95
+ FileDownloadUtils .getThreadPoolName ("MaintainDatabase" );
96
+ new Thread (new Runnable () {
97
+ @ Override
98
+ public void run () {
99
+ maintainDatabase (database .maintainer ());
100
+ }
101
+ }, maintainThreadName ).start ();
92
102
}
93
103
}
94
104
@@ -186,7 +196,7 @@ private static void maintainDatabase(FileDownloadDatabase.Maintainer maintainer)
186
196
|| model .getStatus () == FileDownloadStatus .error
187
197
|| (model .getStatus () == FileDownloadStatus .pending && model
188
198
.getSoFar () > 0 )
189
- ) {
199
+ ) {
190
200
// Ensure can be covered by RESUME FROM BREAKPOINT.
191
201
model .setStatus (FileDownloadStatus .paused );
192
202
}
@@ -275,6 +285,9 @@ private static void maintainDatabase(FileDownloadDatabase.Maintainer maintainer)
275
285
FileDownloadUtils .markConverted (FileDownloadHelper .getAppContext ());
276
286
maintainer .onFinishMaintain ();
277
287
// 566 data consumes about 140ms
288
+ // update by rth: different devices have very large disparity, such as,
289
+ // in my HuaWei Android 8.0, 67 data consumes about 355ms.
290
+ // so, it's better do this action in background thread.
278
291
if (FileDownloadLog .NEED_LOG ) {
279
292
FileDownloadLog .d (FileDownloadDatabase .class ,
280
293
"refreshed data count: %d , delete data count: %d, reset id count:"
0 commit comments