流利说的下载库,
Multitask、MultiThread(MultiConnection)、Breakpoint-resume、High-concurrency、Simple to use、Single/NotSingle-process
https://github.com/lingochamp/FileDownloader
注意:application里的init
// just for open the log in this demo project.
FileDownloadLog.NEED_LOG = BuildConfig.DOWNLOAD_NEED_LOG;
/**
* just for cache Application's Context, and ':filedownloader' progress will NOT be launched
* by below code, so please do not worry about performance.
* @see FileDownloader#init(Context)
*/
FileDownloader.setupOnApplicationOnCreate(this)
.connectionCreator(new FileDownloadUrlConnection
.Creator(new FileDownloadUrlConnection.Configuration()
.connectTimeout(15_000) // set connection timeout.
.readTimeout(15_000) // set read timeout.
))
.commit();
// below codes just for monitoring thread pools in the FileDownloader:
// 监控线程池
IThreadDebugger debugger = ThreadDebugger.install(
ThreadDebuggers.create() /** The ThreadDebugger with known thread Categories **/
// add Thread Category
.add("OkHttp").add("okio").add("Binder")
.add(FileDownloadUtils.getThreadPoolName("Network"), "Network")
.add(FileDownloadUtils.getThreadPoolName("Flow"), "FlowSingle")
.add(FileDownloadUtils.getThreadPoolName("EventPool"), "Event")
.add(FileDownloadUtils.getThreadPoolName("LauncherTask"), "LauncherTask")
.add(FileDownloadUtils.getThreadPoolName("ConnectionBlock"), "Connection")
.add(FileDownloadUtils.getThreadPoolName("RemitHandoverToDB"), "RemitHandoverToDB")
.add(FileDownloadUtils.getThreadPoolName("BlockCompleted"), "BlockCompleted"),
2000, /** The frequent of Updating Thread Activity information **/
new ThreadDebugger.ThreadChangedCallback() {
/**
* The threads changed callback
**/
@Override
public void onChanged(IThreadDebugger debugger) {
// callback this method when the threads in this application has changed.
Log.d(TAG, debugger.drawUpEachThreadInfoDiff());
Log.d(TAG, debugger.drawUpEachThreadSizeDiff());
Log.d(TAG, debugger.drawUpEachThreadSize());
}
});
网友评论