CN112600913A - Download management method based on Android - Google Patents

Download management method based on Android Download PDF

Info

Publication number
CN112600913A
CN112600913A CN202011437043.8A CN202011437043A CN112600913A CN 112600913 A CN112600913 A CN 112600913A CN 202011437043 A CN202011437043 A CN 202011437043A CN 112600913 A CN112600913 A CN 112600913A
Authority
CN
China
Prior art keywords
file
downloading
priority
download
tasks
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011437043.8A
Other languages
Chinese (zh)
Inventor
丁凯
朱卉明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Focus Technology Co Ltd
Original Assignee
Focus Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Focus Technology Co Ltd filed Critical Focus Technology Co Ltd
Priority to CN202011437043.8A priority Critical patent/CN112600913A/en
Publication of CN112600913A publication Critical patent/CN112600913A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/06Protocols specially adapted for file transfer, e.g. file transfer protocol [FTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/34Network arrangements or protocols for supporting network services or applications involving the movement of software or configuration parameters 

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Transfer Between Computers (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

A download management method based on Android comprises the following steps: 1) firstly, the app starts a downloading task, and transmits a priority variable to a downloading management module when the downloading task is started; 2) the downloading task firstly puts the task into a downloading queue, and the high-priority queue is preferentially processed at the front section of the queue; the low priority drain is processed last at the end of the queue. The arrangement rule is as follows: a) ranking the priority high in the front; b) arranging the common priority after the high priority; c) arranging the low priority behind the common priority; determining the level of high priority and the level of low priority by a priority variable; when a plurality of downloading tasks are requested together, starting a plurality of threads to process the downloading tasks simultaneously, and releasing the plurality of threads in time after the downloading tasks are completed; the maximum number of tasks of the thread is set to 5.

Description

Download management method based on Android
Technical Field
The invention relates to the technical field of computer program development, in particular to an android download management technology.
Background
The downloading part is a very common function in the Android development process, and many times, developers can simply implement the downloading part. Therefore, there are many defects, one of which is that the functions are not uniform, and multi-task downloading and feedback of the download state information through broadcasting instead of interface mode are generally not considered.
Because of the design difference and the implementation difference of each designer, redundancy or functional abnormality occurs to the system download management module. The function of continuous transmission of large files or breakpoints is not added, so that the downloading can be repeatedly carried out again under the condition that the downloading is not stable, and the flow overhead is lost.
The prior art does not provide a better method for download management design of Android.
Disclosure of Invention
The invention aims to provide a method for designing an Android download management module in an Android development process, which is standard and free from errors. The determination and execution of the download task is performed by a download management module.
The technical scheme of the invention is that the download management method based on the Android comprises the following steps:
1) firstly, the app starts a downloading task, and transmits a priority variable to a downloading management module when the downloading task is started;
2) the downloading task firstly puts the task into a downloading queue, and the high-priority queue is preferentially processed at the front section of the queue; the low priority drain is processed last at the end of the queue. The arrangement rule is as follows:
a) ranking the priority high in the front;
b) arranging the common priority after the high priority;
c) arranging the low priority behind the common priority;
determining the level of high priority and the level of low priority by a priority variable;
the download management module uses a thread manager, namely a thread pool is arranged to manage the download threads, when a plurality of download tasks are requested together, a plurality of threads are started to process the download tasks at the same time, and the plurality of threads are released in time after the download tasks are completed; there are several modes that can be selected during the use of the thread pool, and the common modes are as follows:
newCachedThreadPool: creating a cacheable thread pool, if the length of the thread pool exceeds the processing requirement, flexibly recovering idle threads, and if the length of the thread pool is not recoverable, newly creating a thread;
or newfixedthreedpool: and a fixed-length thread pool is created, the maximum concurrency number of the threads can be controlled, and the exceeding threads wait in the queue.
Or newscheduled threadpool: and a fixed-length thread pool is created to support timing and periodic task execution.
In the scheme of the invention, a thread manager newCachedThreadPool with a cache function is selected, and the maximum number of the tasks of the threads is set to be 5, so that when the downloading tasks come, at most 5 downloading tasks can be executed simultaneously, and the subsequent tasks can directly use the used cache threads without starting new threads.
If the size of the file needing to be downloaded is smaller than 4M, the file is directly read and written into the file; if the size of the residual file to be downloaded is larger than 1M, the data needs to be read and written into the cache firstly, then the data is written into the file, the downloading progress is updated simultaneously, the page progress is informed in real time, and the data is directly read and written into the file until the size of the residual file to be downloaded is smaller than 4M.
The method has the advantages that the design scheme avoids the defects of the prior art, and the method integrates the advantages of reusability, complete functions, support of breakpoint continuous transmission, real-time feedback of download states and the like. And the downloading of the super large files can be supported, and the abnormal condition of OOM (memory overflow) can not occur in the downloading process.
Through the comprehensive analysis, the scheme has the following properties:
1. supporting multi-task downloading; according to the scheme, through the use of the thread pool, at most 5 tasks can be started at the same time, and at most 5 tasks are supported to be downloaded at the same time.
2. The downloading progress and the downloading state are fed back in real time; the progress of the file downloading state and the final downloading result (failure or success) in the scheme transmit the state to the app interface in real time in the form of an interface. Meanwhile, the app can conveniently acquire the downloaded specific information.
3. The downloading task has priority management; the scheme uses 3 priorities, low, common and high, can effectively rank and order the downloading tasks, and can respond to the high-priority tasks preferentially.
4. The breakpoint continuous transmission is supported; the function of breakpoint transmission can be achieved by using the download information description file. And a part of the data is recorded in the database every time of uploading, so that the data is conveniently uploaded again next time.
5. The large file is downloaded, 1M data is downloaded and written into the file in a slicing mode every time, the file is not read from the memory once and written into the memory once, and therefore the problem of memory overflow can be effectively avoided when the large file is downloaded.
Compared with the prior art, the method has the following remarkable advantages:
the scheme mainly aims to provide a design which is convenient to use, supports the functions of multi-task downloading, real-time callback of downloading information, breakpoint resume, super-large file downloading and the like.
Drawings
Fig. 1 is a general flow chart of the entire functional design. After the downloading task is started, reading the previous downloading information from the original task, then downloading again from the downloaded place, and if the downloading is finished, notifying success through the interface, otherwise, notifying failure.
Fig. 2 is the most important part of the download flow. If the size of the file is smaller than 1M, the file is directly read and written into the file, if the size of the file is larger than 1M, the data needs to be read and written into a cache firstly, then the data is written into the file, meanwhile, the downloading progress is updated, and the page progress is informed in real time.
Detailed Description
Specific implementation logic is described below, and a more detailed portion will be described using a flowchart. FIG. 1 shows: after the downloading task is started, reading the previous downloading information from the original task, then downloading again from the downloaded place, and if the downloading is finished, notifying success through the interface, otherwise, notifying failure.
1. Firstly, the app starts a downloading task, and when the downloading task is started, a priority variable can be transmitted to the downloading management module.
2. The download task will first place the task into the download queue, and the high priority drain will be processed first at the front of the queue. The low priority drain is processed last at the end of the queue. The arrangement rule is as follows:
a) the higher priority is ranked in front.
b) The normal priority is ranked behind the high priority.
c) The low priority is ranked behind the normal priority.
Use of thread pool:
because there are multiple tasks requesting download in common, we cannot simply design a single thread to handle all tasks. In order to improve the execution efficiency, a thread pool is used for managing threads, when a plurality of downloading tasks are requested together, a plurality of threads are started to process simultaneously, and release is carried out in time after the processing is finished. There are several modes that can be selected during the use of the thread pool, and the common modes are as follows:
newCachedThreadPool: and establishing a cacheable thread pool, if the length of the thread pool exceeds the processing requirement, flexibly recovering idle threads, and if the length of the thread pool is not recoverable, newly establishing a thread.
newfixedthreedpool: and a fixed-length thread pool is created, the maximum concurrency number of the threads can be controlled, and the exceeding threads wait in the queue.
newschedulthreadpool: and a fixed-length thread pool is created to support timing and periodic task execution.
In order to improve the utilization rate of threads and not affect the system overhead, a thread manager newCachedThreadPool with a cache function is selected, and the maximum number of the threads is set to 5, so that when a downloading task comes, at most 5 downloading tasks can be executed simultaneously, and a subsequent task does not start a new thread to directly use a previously used cache thread. The processing can greatly save the resource loss of continuously starting the thread of the system, and also reduce the calculation time of the garbage collector for recovering useless resources (starting and recovering the thread).
The processing not only improves the efficiency of processing tasks, but also can repeatedly utilize the threads of the cache because of using the threads of the cache, so that the processing can not cause excessive pressure on the system, thereby achieving a better balance effect.
3. In the request process, the information FileInfo (information that refers to the downloaded file) of the downloaded file is obtained, and the main obtained information is as follows:
a) file download address
b) Name of file and type of file
c) The size of the file is used for conveniently calculating the downloading progress at later stage
After the file download address (url of the downloaded file) is transferred in, you need to splice the download address of the file and transfer it in before downloading.
The size of the file is obtained by reading header information of the file. Generally, a file composition in a computer is divided into 2 parts, a header information part and a content part. The header information part mainly records the attributes of file size, coding, creation time, modification time and the like. The content part is content information recorded by the file. We have this place to get the file size by getting the header information of the file.
4. And storing the acquired file information FileInfo, wherein the file name, the file downloading address, the total size of the file and the size of the downloaded file are mainly stored in the scheme. The scheme directly stores the information to be stored in the sqlite database.
Fig. 2 is the most important part of the download flow.
If the size of the file needing to be downloaded is smaller than 4M, the file is directly read and written into the file; if the size of the residual file to be downloaded is larger than 1M, the data needs to be read and written into the cache firstly, then the data is written into the file, the downloading progress is updated simultaneously, the page progress is informed in real time, and the data is directly read and written into the file until the size of the residual file to be downloaded is smaller than 4M. Updating the download progress may know whether the current download is complete.
Reading a file in the stream, if the file is less than 4M and greater than 4M, performing fragment downloading on the file, downloading 1M data each time and writing the data into the file;
the downloading progress and the downloading state are fed back in real time; the progress of the file downloading state and the final downloading result (failure or success) in the scheme transmit the state to the app interface in real time in the form of an interface. Meanwhile, the app can conveniently acquire the downloaded specific information.
1. The downloading task has priority management; the scheme uses 3 priorities, low, common and high, can effectively rank and order the downloading tasks, and can respond to the high-priority tasks preferentially.
2. The breakpoint continuous transmission is supported; the function of breakpoint transmission can be achieved by using the download information description file. Breakpoint resuming: firstly, the actual size of a file needs to be set in a request head, and meanwhile, the position of the last file downloading is taken out from a database and is also written in the request head, so that in the current request, the downloading of the content can be continuously completed from the previous place until the file is completely downloaded; and a part of the data is recorded in the database every time of uploading, so that the data is conveniently uploaded again next time.
3. The large file is downloaded, 1M data is downloaded and written into the file in a slicing mode every time, the file is not read from the memory once and written into the memory once, and therefore the problem of memory overflow can be effectively avoided when the large file is downloaded.
The process of downloading the large file comprises the following steps:
step one, starting a downloading task and setting the priority of downloading;
step two, acquiring downloading information, and reading out the downloading progress and the file size of the current file from a database;
and step three, writing the acquired downloading information into the request head, and then starting to download the file from the server.
Step four, if the current file is less than 1M, directly writing the current file into the file; if the file is larger than 1M, the data is written into the cache firstly, then the data is written into the file, and meanwhile, the downloading progress is written into the database.
And step five, in the downloading process, informing the downloading progress of the app through the interface, and once the downloading is finished, finishing the informing of the interface. If paused or failed, also via an interface.

Claims (4)

1. A download management method based on Android is characterized by comprising the following steps:
1) firstly, the app starts a downloading task, and transmits a priority variable to a downloading management module when the downloading task is started;
2) the downloading task firstly puts the task into a downloading queue, and the high-priority queue is preferentially processed at the front section of the queue; the low priority drain is processed last at the end of the queue. The arrangement rule is as follows:
a) ranking the priority high in the front;
b) arranging the common priority after the high priority;
c) arranging the low priority behind the common priority;
determining the level of high priority and the level of low priority by a priority variable;
the download management module uses a thread manager, namely a thread pool is arranged to manage the download threads, when a plurality of download tasks are requested together, a plurality of threads are started to process the download tasks at the same time, and the plurality of threads are released in time after the download tasks are completed; in the using process of the thread pool, a thread manager newCachedThreadPool with a cache function is selected, and the maximum number of the tasks of the threads is set to be 5, so that when downloading tasks come, at most 5 downloading tasks can be executed simultaneously, and subsequent tasks do not start new threads and directly use the used cache threads.
2. The Android-based download management method as recited in claim 1, wherein in the request process, the information FileInfo of the downloaded file is obtained as follows:
a) file download address
b) Name of file and type of file
c) The size of the file is that the file download address used for conveniently calculating the download progress in the later period, namely the download address of the file needs to be spliced and transmitted before downloading after the url of the downloaded file is transmitted; storing the acquired file information FileInfo, and storing a file name, a file downloading address, the total size of the file and the size of the downloaded file; the information to be stored is stored directly in the sqlite database.
3. The Android-based download management method of claim 1, wherein the size of the file is obtained by reading header information of the file; the header information part records the size, coding, creating time and modifying time attributes of the file; the content part is content information recorded by the file.
4. The Android-based download management method of claim 1, wherein if the size of the file to be downloaded is less than 4M, the file is directly read and written into the file; if the size of the residual file to be downloaded is larger than 1M, the data needs to be read and written into the cache firstly, then the data is written into the file, the downloading progress is updated simultaneously, the page progress is informed in real time, and the data is directly read and written into the file until the size of the residual file to be downloaded is smaller than 4M.
CN202011437043.8A 2020-12-07 2020-12-07 Download management method based on Android Pending CN112600913A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011437043.8A CN112600913A (en) 2020-12-07 2020-12-07 Download management method based on Android

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011437043.8A CN112600913A (en) 2020-12-07 2020-12-07 Download management method based on Android

Publications (1)

Publication Number Publication Date
CN112600913A true CN112600913A (en) 2021-04-02

Family

ID=75191586

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011437043.8A Pending CN112600913A (en) 2020-12-07 2020-12-07 Download management method based on Android

Country Status (1)

Country Link
CN (1) CN112600913A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113778673A (en) * 2021-08-27 2021-12-10 深圳市广和通无线股份有限公司 Data processing method, storage medium and device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030145088A1 (en) * 2002-01-31 2003-07-31 International Business Machines Corporation Method and system for splitting a bandwidth among a plurality of network transactions
CN106445665A (en) * 2016-09-19 2017-02-22 武汉斗鱼网络科技有限公司 Method and tool for system file downloading applied to android system
CN111104387A (en) * 2019-11-22 2020-05-05 苏州浪潮智能科技有限公司 Method and device for acquiring data set on server

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030145088A1 (en) * 2002-01-31 2003-07-31 International Business Machines Corporation Method and system for splitting a bandwidth among a plurality of network transactions
CN106445665A (en) * 2016-09-19 2017-02-22 武汉斗鱼网络科技有限公司 Method and tool for system file downloading applied to android system
CN111104387A (en) * 2019-11-22 2020-05-05 苏州浪潮智能科技有限公司 Method and device for acquiring data set on server

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113778673A (en) * 2021-08-27 2021-12-10 深圳市广和通无线股份有限公司 Data processing method, storage medium and device
CN113778673B (en) * 2021-08-27 2024-02-09 深圳市广和通无线股份有限公司 Data processing method, storage medium and apparatus

Similar Documents

Publication Publication Date Title
CN106445665B (en) A kind of system file method for down loading and download tool applied to Android system
US9021303B1 (en) Multi-threaded in-memory processing of a transaction log for concurrent access to data during log replay
CN110895484A (en) Task scheduling method and device
CN110895487B (en) Distributed task scheduling system
WO2019223599A1 (en) Data acquisition system and method, node device and storage medium
WO2019109854A1 (en) Data processing method and device for distributed database, storage medium, and electronic device
CN110427258B (en) Resource scheduling control method and device based on cloud platform
CN112465046B (en) Method, system, equipment and medium for artificial intelligence training of mass small files
CN110895483A (en) Task recovery method and device
CN110895486B (en) Distributed task scheduling system
WO2020010724A1 (en) Front-end static resource management method, apparatus, computer device and storage medium
US20170085653A1 (en) Method, device and system for message distribution
CN110895488A (en) Task scheduling method and device
CN107798111B (en) Method for exporting data in large batch in distributed environment
CN115086298A (en) File transmission method and device
CN112600913A (en) Download management method based on Android
CN106874343B (en) Data deletion method and system for time sequence database
CN111736907A (en) Data analysis method of self-adaptive low-delay memory computing engine
CN111061690A (en) RAC-based database log file reading method and device
CN115185679A (en) Task processing method and device for artificial intelligence algorithm, server and storage medium
CN109697112B (en) Distributed intensive one-stop operating system and implementation method
CN113438275B (en) Data migration method and device, storage medium and data migration equipment
WO2019136843A1 (en) Method, storage medium, device and system for starting page in android system
CN108121514B (en) Meta information updating method and device, computing equipment and computer storage medium
CN115114247A (en) File data processing method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination