CN112671816B - File downloading method, device, equipment and medium - Google Patents

File downloading method, device, equipment and medium Download PDF

Info

Publication number
CN112671816B
CN112671816B CN201910982645.2A CN201910982645A CN112671816B CN 112671816 B CN112671816 B CN 112671816B CN 201910982645 A CN201910982645 A CN 201910982645A CN 112671816 B CN112671816 B CN 112671816B
Authority
CN
China
Prior art keywords
downloading
thread
progress
file
task
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.)
Active
Application number
CN201910982645.2A
Other languages
Chinese (zh)
Other versions
CN112671816A (en
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.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen 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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201910982645.2A priority Critical patent/CN112671816B/en
Publication of CN112671816A publication Critical patent/CN112671816A/en
Application granted granted Critical
Publication of CN112671816B publication Critical patent/CN112671816B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Information Transfer Between Computers (AREA)

Abstract

The invention discloses a file downloading method, a file downloading device, file downloading equipment and a file downloading medium. The method comprises the following steps: in response to a received downloading request, segmenting a file to be downloaded into at least two fragment files; creating a progress updating thread and at least two downloading threads; executing a downloading task of the corresponding fragment file by using the downloading thread; sending a task progress message to the progress updating thread by using the downloading thread, wherein the task progress message represents the execution condition of the downloading task; and updating the downloading progress of the file to be downloaded by utilizing the progress updating thread. The invention can ensure the effective execution of the downloading task, the effective update of the downloading progress and the downloading speed of the file to be downloaded.

Description

File downloading method, device, equipment and medium
Technical Field
The present invention relates to the field of internet communications technologies, and in particular, to a method, an apparatus, a device, and a medium for downloading a file.
Background
With the development of internet communication technology, more and more convenience is brought to daily life and work of people. People can browse various information on the Internet and can collect the information according to the requirements of the people. Among many information collection methods, file downloading is the most common information collection method.
File downloading may be performed using a fragmented download technique. For example, a file to be downloaded is equally divided into n pieces, and then n threads are started, and each thread downloads one piece. Besides executing the downloading task of the corresponding fragments, the threads also need to update the downloading progress of the files to be downloaded. For example, after each thread downloads a portion of the content, an update of the download progress is required. If multiple threads are updating the download progress at the same time, a progress error due to thread synchronization may occur (e.g., an update of one thread may be overwritten by an update of another thread). In order to solve the problem, in the prior art, when one thread is updating the downloading progress, the data corresponding to the downloading progress is locked; and after the updating is finished, releasing lock processing is carried out on the data corresponding to the downloading progress. During the time that the data is locked, another thread can lock and operate on this data only after waiting for the lock to be released.
However, due to the introduction of the lock, once the lock mixing occurs, there is a hidden danger of deadlock (for example, when the thread 1 holds the lock 1 and waits for the lock 2, the thread 2 holds the lock 2 and waits for the lock 1, and the threads wait for each other, and the execution of the corresponding download task is blocked). Meanwhile, during the locking period, the corresponding thread needs to wait for the release of the lock to continue downloading the task, which affects the overall speed of downloading the file to be downloaded. Therefore, there is a need to provide a more efficient download scheme for files to be downloaded.
Disclosure of Invention
In order to solve the problems that the downloading speed is slow, the updating of the downloading progress is easy to be abnormal and the like when the prior art is applied to downloading files, the invention provides a file downloading method, a device, equipment and a medium, wherein the method comprises the following steps:
in one aspect, the present invention provides a file downloading method, where the method includes:
in response to a received downloading request, segmenting a file to be downloaded into at least two fragment files;
creating a progress updating thread and at least two downloading threads;
executing a downloading task of the corresponding fragment file by using the downloading thread;
sending a task progress message to the progress updating thread by using the downloading thread, wherein the task progress message represents the execution condition of the downloading task;
and updating the downloading progress of the file to be downloaded by utilizing the progress updating thread.
Another aspect provides a file downloading apparatus, including:
a cutting module: the device is used for responding to the received downloading request and segmenting the file to be downloaded into at least two fragmented files;
a thread creation module: the system comprises a process updating thread and at least two downloading threads, wherein the process updating thread and the at least two downloading threads are established;
a downloading module: the downloading task is used for executing the corresponding fragment file by utilizing the downloading thread;
a message sending module: the system comprises a downloading thread, a progress updating thread and a task progress message, wherein the downloading thread is used for sending the task progress message to the progress updating thread, and the task progress message represents the execution condition of the downloading task;
an update module: and the download progress of the file to be downloaded is updated by utilizing the progress updating thread.
Another aspect provides an electronic device comprising a processor and a memory, the memory having stored therein at least one instruction, at least one program, a set of codes, or a set of instructions, which is loaded and executed by the processor to implement the file download method as described above.
Another aspect provides a computer readable storage medium having stored therein at least one instruction, at least one program, set of codes, or set of instructions, which is loaded and executed by a processor to implement the file download method as described above.
The file downloading method, the device, the equipment and the medium provided by the invention have the following technical effects:
the invention creates an independent progress updating thread to update the downloading progress of the file to be downloaded, and creates at least two downloading threads to finish the downloading of the file to be downloaded. Each downloading thread only needs to execute the downloading task of the corresponding fragment file, and does not need to execute the updating task of the downloading progress. Therefore, the 'lock' can be directly prevented from being introduced into the downloading thread from the architecture, and the 'deadlock' is further avoided. The method and the device can ensure the effective execution of the downloading task, ensure the effective update of the downloading progress and improve the downloading speed of the file to be downloaded.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions and advantages of the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and other drawings can be obtained by those skilled in the art without creative efforts.
FIG. 1 is a schematic diagram of an application environment provided by an embodiment of the invention;
fig. 2 is a flowchart illustrating a file downloading method according to an embodiment of the present invention;
fig. 3 is a schematic flowchart of a file downloading method according to an embodiment of the present invention;
fig. 4 is a schematic flowchart of a process for updating the download progress of the file to be downloaded by using the progress updating thread according to the embodiment of the present invention;
fig. 5 is a schematic flowchart of a file downloading method according to an embodiment of the present invention;
fig. 6 is a schematic flowchart of updating the download progress of the file to be downloaded by using the progress updating thread according to the embodiment of the present invention;
fig. 7 is a flowchart illustrating a file downloading method according to an embodiment of the present invention;
fig. 8 is a block diagram illustrating a file downloading apparatus according to an embodiment of the present invention;
fig. 9 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be obtained by a person skilled in the art without any inventive step based on the embodiments of the present invention, are within the scope of the present invention.
It should be noted that the terms "comprises" and "comprising," and any variations thereof, in the description and claims of this invention and in the drawings described above, are intended to cover non-exclusive inclusions, such that a process, method, system, article, or server that comprises a list of steps or elements is not necessarily limited to those steps or elements explicitly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
Referring to fig. 1, fig. 1 is a schematic diagram of an application environment according to an embodiment of the present invention, which may include a client 01 and a server 02, where the client and the server are connected through a network. And the user downloads the file to be downloaded from the server through the client. It should be noted that fig. 1 is only an example.
Specifically, the client 01 may include a physical device such as a smart phone, a desktop computer, a tablet computer, a notebook computer, a digital assistant, a smart wearable device, etc., or may include software running in the physical device, such as a web page provided by some service providers to the user, or may provide applications provided by the service providers to the user.
Specifically, the server 02 may include a server that operates independently, or a distributed server, or a server cluster composed of a plurality of servers. The server 02 may comprise a network communication unit, a processor and a memory, etc.
In practical application, the client may correspond to a video application, and the file to be downloaded may be a video. The client may correspond to a plug-in system, and the file to be downloaded may be a plug-in. The client may correspond to an application distribution platform, and the file to be downloaded may be an application. The client may correspond to a network disk, and the file to be downloaded may be a network disk resource. Of course, the client is not limited to the above, and the file to be downloaded is not limited to the above.
A specific embodiment of a file downloading method according to the present invention is described below, and fig. 2 and 7 are schematic flow charts of a file downloading method provided by an embodiment of the present invention, and the present specification provides the method operation steps described in the embodiment or the flow charts, but may include more or less operation steps based on conventional or non-creative labor. The order of steps recited in the embodiments is merely one manner of performing the steps in a multitude of orders and does not represent the only order of execution. In actual system or server product execution, sequential execution or parallel execution (e.g., parallel processor or multithreaded processing environments) may occur according to the embodiments or methods shown in the figures. Specifically, as shown in fig. 2 and 7, the method may include:
s201: in response to a received downloading request, segmenting a file to be downloaded into at least two fragment files;
in the embodiment of the present invention, the download request includes a file identifier representing the file to be downloaded, and of course, the download request may also include a user account identifier. And the client downloads the file to be downloaded from the server according to the received downloading request. The file to be downloaded may comprise at least one selected from the group consisting of a document file type, a multimedia file (such as image, audio, video) type, a computer program file (such as executable) type, and the like. Accordingly, the file to be downloaded may include at least one selected from the group consisting of a text format (txt), a portable document format (pdf), a portable network graphics format (png), a markup image format (tga), a portable pixel format (ppm), an image interchange format (gif), MP3 (an audio format), MPEG (an audio, video format), and the like.
In order to ensure the efficiency of downloading the file to be downloaded, the file to be downloaded may be divided into at least two fragmented files. And averagely segmenting the files to be downloaded according to the total data range of the files to be downloaded. For example, the total data range of the file to be downloaded is 10000kb (kilobytes), and the file to be downloaded is equally divided into 100 fragmented files, so that the data range corresponding to each fragmented file is 100 kb. And carrying out file type dimension-based segmentation on the file to be downloaded according to the file type related to the file to be downloaded. And according to the file format related to the file to be downloaded, carrying out file format dimension-based segmentation on the file to be downloaded.
In another specific embodiment, the download request may be triggered by a user based on a corresponding user interaction interface of the client. Such as by the user triggering the download request via a "download" button on a user interaction page. Of course, the trigger form of the download request may also include a sound trigger (a microphone collects sound, triggered by extracting voice with a specific meaning), an image trigger (a camera collects image data, triggered by extracting an expression or a gesture with a specific meaning).
S202: creating a progress updating thread and at least two downloading threads;
in the embodiment of the invention, the progress updating thread created by the client is used for updating the downloading progress of the file to be downloaded, and the downloading thread created by the client is used for finishing downloading the file to be downloaded. The file to be downloaded is split into at least two (e.g., n) sliced files, and accordingly, at least two (e.g., n) download threads are created. Considering the influence of the downloading thread on the resource processing overhead of the CPU (central processing unit) when executing the downloading task and the corresponding relationship between the number of the downloading threads and the number of the fragmented files, the specific splitting manner of the file to be downloaded may be determined in the foregoing step S201 by combining the resource processing overhead factor of the CPU.
In a specific embodiment, the creating a progress update thread further includes: creating a loop object (Looper) in the progress updating thread; creating a Message Queue (MQ) using the cyclic object; and constructing a thread communication mechanism (a Handler mechanism) based on the circular object and the message queue. For a client corresponding to an Android system, a Handler mechanism is used as an Android message processing mechanism, and communication can be carried out among threads through the Handler mechanism. The threads which communicate based on the Handler mechanism can belong to the same process, the threads which communicate based on the Handler mechanism can correspond to a main thread and sub-threads, and the threads which communicate based on the Handler mechanism can correspond to two sub-threads. The underlying MessageQueue and Looper support is needed to build the Handler mechanism.
The progress updating thread is constructed with a Handler mechanism, and a downloading thread needing to communicate with the progress updating thread can call a messaging function (such as sendMessage (), a messaging function, and the like) to send a message to the progress updating thread by holding a reference of the Handler mechanism.
Specifically, the initial progress updating thread can be successfully upgraded to a Looper thread by calling Looper. Looper can form a binding relationship with the current thread, and at the same time, Looper can create a MessageQueue. Therefore, the progress updating thread can only have one Looper and one MessageQueue, and meanwhile, the Looper (calling Looper. Loop ()) (a thread starting function; based on the starting of the thread corresponding to the function, the thread can continuously take out the messages at the head of the queue from the MQ of the thread to execute related tasks)) enables the MessageQueue to be circulated.
S203: executing a downloading task of the corresponding fragment file by using the downloading thread;
in the embodiment of the present invention, in combination with the foregoing, a file to be downloaded is divided into at least two fragment files, a download task of the corresponding fragment file is executed by using the download thread, and each download thread downloads one fragment file.
When a client receives a download request triggered by a user, the client sends a download application to a corresponding server, specifically, a download thread sends a fragment file download application to the server, and the fragment file download application carries a file identifier of a fragment file. The server receives the application for downloading the fragment file, and according to the file identifier of the fragment file, the server can acquire the corresponding fragment file based on the stored file identifier-file correspondence, and send the acquired fragment file to the client.
S204: sending a task progress message to the progress updating thread by using the downloading thread, wherein the task progress message represents the execution condition of the downloading task;
in the embodiment of the present invention, each download thread may generate a task progress message based on a dimension of a downloaded data range (for example, 32kb each download, a data range corresponding to the download task is completed), a time dimension (for example, every second), and the like. Of course, the dimension parameters used to generate the task progress message may be used in combination. The task progress message generated by each downloading thread represents the self-execution downloading task, namely the self-downloading progress of the corresponding fragment file. The progress updating thread can manage the task of updating the downloading progress of the file to be downloaded according to the received task progress messages from the downloading threads.
In a specific embodiment, as shown in fig. 7, in combination with the construction of the Handler mechanism in step S202, the download thread sends the task progress message to the message queue according to the thread communication mechanism. The circular object and the message queue exist in the progress updating thread, and the downloading thread can throw the task progress message into the message queue through a Handler mechanism.
The MessageQueue can store a large number of messages, and because only one message can be processed by one progress thread at the same time, the data structure inside the MessageQueue is set as a one-way linked list, so that the messages to be processed can be stored in sequence, and then the messages are taken out one by one for execution of related tasks. The operation of adding (inserting) and deleting (deleting) can be conveniently carried out on the message queue by means of the single linked list, and the operation complexity is reduced.
In another specific embodiment, as shown in fig. 3, the sending, by using the download thread, a task progress message to the progress update thread further includes:
s301: monitoring, by the download thread, an execution state of the download task;
for example, the downloading thread a executes a downloading task 1, and the downloading task 1 is to download the fragmented file a. The total data range of the fragments of the fragment file A is 100 kb. When downloading the related content data from the fragment file a, the downloading thread a may store the downloaded content data in a storage area (buffer) corresponding to the downloading thread a. The downloading thread A monitors the execution state of the downloading task 1 and can monitor the storage condition of the content data in the corresponding storage area.
S302: determining, by the download thread, a current download data range corresponding to the fragmented file based on the execution state;
and the downloading thread A can determine the current downloading data range corresponding to the fragment file A according to the storage condition of the content data in the corresponding storage region. The current downloaded data range indicates the downloaded data range of the fragment file A corresponding to the time point of the last task progress reporting and the current time point.
S303: when the current downloading data range meets the requirement of a data range threshold, the downloading thread generates the corresponding task progress message based on the current downloading data range;
the data range threshold value can be taken to represent the data range which needs to be reported each time the task progress is carried out. The data range threshold may be 32kb, although other values may be set. And when the current downloading data range is larger than or equal to 32kb, generating the corresponding task progress message by the downloading thread A based on the current downloading data range. And when the current downloading data range is less than 32kb, the downloading thread A does not generate the task progress message, but continues to download the content data corresponding to the fragment file A.
S304: and sending the task progress message to the progress updating thread by the downloading thread.
In addition to the downloading thread a executing the downloading task 1, the downloading thread B executes the downloading task 2 (the downloading task 2 is to download the fragmented file B), the downloading thread C executes the downloading task 3 (the downloading task 3 is to download the fragmented file C), and so on. The data range threshold for each download thread may be the same (e.g., 32kb) or different. The time for each downloading thread to generate the corresponding task progress message may be different, so that the time for each downloading thread to send the corresponding task progress message to the progress updating thread is also different, correspondingly, the progress updating thread receives the task progress messages from each downloading thread at different time, and then the progress updating thread may execute the related tasks based on the time sequence for receiving the task progress messages.
Further, the generating, by the download thread, the corresponding task progress message based on the current download data range may further include: when a data reading completion message returned by a server is received, the downloading thread generates a corresponding task progress message based on the current downloading data range; and the data reading completion message represents that the content data corresponding to the fragmented file is completely read.
For example, the total data range of the fragments of the fragment file a is 100kb, and the downloaded data range is 96kb (three task progress messages are generated corresponding to three task progress reporting time points). When the current download data range is 4kb (smaller than the data range threshold (32kb)), if the task progress message is generated only based on the dimension of downloading 32kb, the download thread does not generate the task progress message, and the content data corresponding to the fragment file a is actually downloaded, which affects the accuracy of the update download progress of the progress update thread.
S205: and updating the downloading progress of the file to be downloaded by utilizing the progress updating thread.
In the embodiment of the invention, the progress updating thread updates the downloading progress of the file to be downloaded according to the received task progress message. This allows the management of the download progress by a single thread. The downloading thread is not needed to execute the downloading task of the corresponding fragment file and the updating task of the downloading progress, the downloading thread can be concentrated in executing the corresponding downloading task, and the multithreading fragment downloading capacity can be improved.
In a specific embodiment, the loop object and the message queue may exist in the progress update thread in conjunction with the construction of the Handler mechanism in step S202. As shown in fig. 4, the updating the download progress of the file to be downloaded by using the progress updating thread includes:
s401: determining a timestamp corresponding to the task progress message by the progress updating thread;
the progress updating thread receives task progress messages from all the downloading threads at different time, the progress updating thread determines a timestamp corresponding to the task progress messages, and the timestamp can point to the time when the progress updating thread receives the task progress messages.
S402: inserting the task progress message into the message queue by the progress updating thread according to the timestamp corresponding to the task progress message;
and throwing the task progress message into a message queue by a corresponding downloading thread based on a Handler mechanism. The progress update thread may call a message insertion function (such as a message queue. enqueue message ()), and insert the task progress message into the message queue according to a timestamp corresponding to the task progress message.
S403: circularly executing the following steps by the progress updating thread until the message queue is empty: extracting the task progress message corresponding to the earliest timestamp from the message queue by using the circulating object as a target task progress message, and updating the downloading progress of the file to be downloaded according to the target task progress message;
referring to fig. 7, specifically, loop () (a thread start function; based on the thread start corresponding to the function, the thread can continuously fetch the Message at the head of the queue from its MQ to execute the relevant task) is called by the loop object to open a dead loop, so that the Message (corresponding to the task progress Message) can be continuously fetched from the Message queue inside the loop.
The progress updating thread may call a message reading function (e.g., message queue. next ()), read a corresponding target task progress message (a process of deleting the message is also performed while reading), and update the downloading progress according to the last downloading progress recorded information (e.g., the history time corresponding to the last downloading progress update, the total data range corresponding to the file to be downloaded, and the downloaded data range corresponding to the file to be downloaded).
In another specific embodiment, as shown in fig. 5, the task progress message includes a current data downloading range, where the current data downloading range indicates a downloaded data range of the fragmented file corresponding to a time point of last task progress reporting and a time point of current task progress reporting. Correspondingly, the updating the downloading progress of the file to be downloaded by using the progress updating thread includes:
s501: acquiring a total data range corresponding to the file to be downloaded by the progress updating thread;
for example, the total data range corresponding to the file to be downloaded is a.
S502: acquiring a downloaded data range corresponding to the file to be downloaded by the progress updating thread;
for example, the downloaded data range corresponding to the file to be downloaded is B.
S503: and updating the downloading progress of the file to be downloaded by the progress updating thread according to the total data range, the downloaded data range corresponding to the file to be downloaded and the current downloading data range.
For example, if the current download data range is C, the download progress of the file to be downloaded is (B + C)/a, and the download progress is taken as the current download progress.
Further, as shown in fig. 6, the updating the download progress of the file to be downloaded by using the progress updating thread further includes:
s601: obtaining the historical time corresponding to the last downloading progress update by the progress update thread;
and the progress updating thread records the time of the downloading progress updating every time the downloading progress task is updated.
S602: obtaining time to be calculated by the progress updating thread according to the current time and the historical time;
the time to be calculated is the current time-the historical time.
S603: and obtaining the current downloading speed of the file to be downloaded by the progress updating thread according to the data downloading range and the time to be calculated.
The current download speed is the current download data range/(current time-historical time). Based on the obtained downloading progress and the current downloading speed of the file to be downloaded, the downloading progress and the current downloading speed can be visually presented in a user interaction interface corresponding to the client, such as a progress bar and a progress ring, so that a user can intuitively perceive the current downloading condition in real time.
As can be seen from the technical solutions provided in the embodiments of the present specification, an independent progress updating thread is created to update the downloading progress of the file to be downloaded, and at least two downloading threads are created to complete downloading of the file to be downloaded. Each downloading thread only needs to execute the downloading task of the corresponding fragment file, and does not need to execute the updating task of the downloading progress. Therefore, the 'lock' can be directly prevented from being introduced into the downloading thread from the architecture, and the 'deadlock' condition is further avoided. The situation that the downloading thread is in the waiting state is reduced, and the processing resource and the network bandwidth of the CPU can be more reasonably and fully utilized. The method and the device can ensure the effective execution of the downloading task, ensure the effective updating of the downloading progress and improve the downloading speed of the file to be downloaded.
An embodiment of the present invention further provides a file downloading device, and as shown in fig. 8, the file downloading device includes:
the slicing module 810: the file downloading system is used for responding to a received downloading request and segmenting a file to be downloaded into at least two fragmented files;
the thread creation module 820: the system comprises a process updating thread and at least two downloading threads, wherein the process updating thread and the at least two downloading threads are established;
the download module 830: the downloading thread is used for executing a downloading task of the corresponding fragment file;
the message sending module 840: the system comprises a downloading thread, a progress updating thread and a task progress message, wherein the downloading thread is used for sending a task progress message to the progress updating thread, and the task progress message represents the execution condition of the downloading task;
the update module 850: and the download progress updating thread is used for updating the download progress of the file to be downloaded.
It should be noted that the device and method embodiments in the device embodiment are based on the same inventive concept.
An embodiment of the present invention provides an electronic device, which includes a processor and a memory, where at least one instruction, at least one program, a code set, or a set of instructions is stored in the memory, and the at least one instruction, the at least one program, the code set, or the set of instructions is loaded and executed by the processor to implement the file downloading method provided by the foregoing method embodiment.
Further, fig. 9 shows a schematic hardware structure of an electronic device for implementing the file downloading method provided by the embodiment of the present invention, where the device may participate in forming or including the apparatus provided by the embodiment of the present invention. As shown in fig. 9, the apparatus 90 may include one or more (shown here as 902a, 902b, … …, 902 n) processors 902 (the processors 902 may include, but are not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA, etc.), a memory 904 for storing data, and a transmission device 906 for communication functions. In addition, the method can also comprise the following steps: a display, an input/output interface (I/O interface), a Universal Serial Bus (USB) port (which may be included as one of the ports of the I/O interface), a network interface, a power source, and/or a camera. It will be understood by those skilled in the art that the structure shown in fig. 9 is only an illustration and is not intended to limit the structure of the electronic device. For example, the electronic device 90 may also include more or fewer components than shown in FIG. 9, or have a different configuration than shown in FIG. 9.
It should be noted that the one or more processors 902 and/or other data processing circuitry described above may be referred to generally herein as "data processing circuitry". The data processing circuitry may be embodied in whole or in part in software, hardware, firmware, or any combination thereof. Further, the data processing circuit may be a single stand-alone processing module, or incorporated, in whole or in part, into any of the other elements in the electronic device 90 (or mobile device). As referred to in the embodiments of the application, the data processing circuit acts as a processor control (e.g. selection of variable resistance termination paths connected to the interface).
The memory 904 may be used for storing software programs and modules of application software, such as program instructions/data storage devices corresponding to the file downloading method described in the embodiment of the present invention, and the processor 902 executes various functional applications and data processing by operating the software programs and modules stored in the memory 94, so as to implement the file downloading method described above. The memory 904 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 904 may further include memory located remotely from the processor 902, which may be connected to the electronic device 90 via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmitting means 906 is used for receiving or sending data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider of the electronic device 90. In one example, the transmission device 906 includes a network adapter (NIC) that can be connected to other network devices through a base station so as to communicate with the internet. In one example, the transmitting device 906 can be a Radio Frequency (RF) module for communicating with the internet via wireless means.
The display may be, for example, a touch screen type Liquid Crystal Display (LCD) that may enable a user to interact with a user interface of the electronic device 90 (or mobile device).
Embodiments of the present invention also provide a storage medium, which may be disposed in an electronic device to store at least one instruction, at least one program, a code set, or a set of instructions related to implementing a file downloading method in the method embodiments, where the at least one instruction, the at least one program, the code set, or the set of instructions are loaded and executed by the processor to implement the file downloading method provided by the above method embodiments.
Alternatively, in this embodiment, the storage medium may be located in at least one network server of a plurality of network servers of a computer network. Optionally, in this embodiment, the storage medium may include but is not limited to: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic or optical disk, and other various media capable of storing program codes.
It should be noted that: the precedence order of the above embodiments of the present invention is only for description, and does not represent the merits of the embodiments. And that specific embodiments have been described above. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims can be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the device and electronic apparatus embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and reference may be made to some descriptions of the method embodiments for relevant points.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the storage medium may be a read-only memory, a magnetic disk or an optical disk.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and should not be taken as limiting the scope of the present invention, which is intended to cover any modifications, equivalents, improvements, etc. within the spirit and scope of the present invention.

Claims (9)

1. A method for downloading a file, the method comprising:
in response to a received downloading request, segmenting a file to be downloaded into at least two fragment files;
creating a progress updating thread and at least two downloading threads; the at least two downloading threads correspond to the at least two fragment files one to one;
creating a cycle object in the progress updating thread, creating a message queue by using the cycle object, and constructing a thread communication mechanism based on the cycle object and the message queue; the message queue is used for storing task progress messages to be read in sequence;
executing a downloading task of the corresponding fragment file by using the downloading thread;
sending a task progress message corresponding to the downloading thread to the message queue by using the downloading thread based on the thread communication mechanism, wherein the task progress message corresponding to the downloading thread represents the execution condition of a downloading task corresponding to the downloading thread, and the task progress message corresponding to the downloading thread comprises the current downloading data range of the downloading thread;
and updating the downloading progress of the file to be downloaded by utilizing the progress updating thread.
2. The method of claim 1, wherein:
before the updating the downloading progress of the file to be downloaded by using the progress updating thread, the method further comprises the following steps:
determining a timestamp corresponding to the task progress message by the progress updating thread;
inserting the task progress message into the message queue by the progress updating thread according to the timestamp corresponding to the task progress message;
the updating the downloading progress of the file to be downloaded by using the progress updating thread comprises the following steps:
circularly executing the following steps by the progress updating thread until the message queue is empty: and extracting the task progress message corresponding to the earliest timestamp from the message queue by using the circulating object as a target task progress message, and updating the downloading progress of the file to be downloaded according to the target task progress message.
3. The method according to claim 1, wherein the task progress message includes a current download data range indicating a downloaded data range of the fragmented file corresponding between a last task progress reporting time point and a current task progress reporting time point;
correspondingly, the updating the downloading progress of the file to be downloaded by using the progress updating thread includes:
acquiring a total data range corresponding to the file to be downloaded by the progress updating thread;
acquiring a downloaded data range corresponding to the file to be downloaded by the progress updating thread;
and updating the downloading progress of the file to be downloaded by the progress updating thread according to the total data range, the downloaded data range corresponding to the file to be downloaded and the current downloading data range.
4. The method of claim 3, further comprising:
obtaining the historical time corresponding to the last downloading progress update by the progress update thread;
obtaining time to be calculated by the progress updating thread according to the current time and the historical time;
and obtaining the current downloading speed of the file to be downloaded by the progress updating thread according to the data downloading range and the time to be calculated.
5. The method of claim 1, wherein before sending, by the downloading thread, a task progress message corresponding to the downloading thread to the message queue based on the thread communication mechanism, the method further comprises:
monitoring, by the download thread, an execution state of the download task;
determining, by the download thread, a current download data range of the corresponding fragmented file based on the execution state;
and when the current downloading data range meets the requirement of a data range threshold, the downloading thread generates the task progress message corresponding to the downloading thread based on the current downloading data range.
6. The method of claim 5, wherein before sending, by the downloading thread, a task progress message corresponding to the downloading thread to the message queue based on the thread communication mechanism, the method further comprises:
when a data reading completion message returned by a server is received, the downloading thread generates the task progress message corresponding to the downloading thread based on the current downloading data range;
and the data reading completion message represents that the content data of the corresponding fragment file is completely read.
7. A file download apparatus, characterized in that the apparatus comprises:
a cutting module: the device is used for responding to the received downloading request and segmenting the file to be downloaded into at least two fragmented files;
a thread creation module: the system comprises a progress updating thread and at least two downloading threads, wherein the progress updating thread is used for creating a loop object, creating a message queue by using the loop object and constructing a thread communication mechanism based on the loop object and the message queue; the at least two downloading threads correspond to the at least two fragment files one by one, and the message queue is used for storing task progress messages to be read in sequence;
a downloading module: the downloading thread is used for executing a downloading task of the corresponding fragment file;
a message sending module: the message queue is used for sending a task progress message corresponding to the downloading thread to the message queue by using the downloading thread based on the thread communication mechanism, wherein the task progress message corresponding to the downloading thread represents the execution condition of the downloading task corresponding to the downloading thread, and the task progress message corresponding to the downloading thread comprises the current downloading data range of the downloading thread;
an updating module: and the download progress updating thread is used for updating the download progress of the file to be downloaded.
8. An electronic device, comprising a processor and a memory, wherein at least one instruction, at least one program, a set of codes, or a set of instructions is stored in the memory, and the at least one instruction, the at least one program, the set of codes, or the set of instructions is loaded and executed by the processor to implement the file download method according to any of claims 1-6.
9. A computer readable storage medium having stored therein at least one instruction, at least one program, a set of codes, or a set of instructions, which is loaded and executed by a processor to implement the file download method according to any of claims 1-6.
CN201910982645.2A 2019-10-16 2019-10-16 File downloading method, device, equipment and medium Active CN112671816B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910982645.2A CN112671816B (en) 2019-10-16 2019-10-16 File downloading method, device, equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910982645.2A CN112671816B (en) 2019-10-16 2019-10-16 File downloading method, device, equipment and medium

Publications (2)

Publication Number Publication Date
CN112671816A CN112671816A (en) 2021-04-16
CN112671816B true CN112671816B (en) 2022-07-22

Family

ID=75400609

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910982645.2A Active CN112671816B (en) 2019-10-16 2019-10-16 File downloading method, device, equipment and medium

Country Status (1)

Country Link
CN (1) CN112671816B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104915227A (en) * 2015-05-25 2015-09-16 努比亚技术有限公司 Multi-source and multithread software upgrading method and system
WO2017084313A1 (en) * 2015-11-17 2017-05-26 乐视控股(北京)有限公司 File downloading method and apparatus, and electronic device
CN108566417A (en) * 2018-03-22 2018-09-21 四川长虹电器股份有限公司 A kind of multithread breakpoint continued transmission download system based on android system and method

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104915227A (en) * 2015-05-25 2015-09-16 努比亚技术有限公司 Multi-source and multithread software upgrading method and system
WO2017084313A1 (en) * 2015-11-17 2017-05-26 乐视控股(北京)有限公司 File downloading method and apparatus, and electronic device
CN108566417A (en) * 2018-03-22 2018-09-21 四川长虹电器股份有限公司 A kind of multithread breakpoint continued transmission download system based on android system and method

Also Published As

Publication number Publication date
CN112671816A (en) 2021-04-16

Similar Documents

Publication Publication Date Title
CN108023908B (en) Data updating method, device and system
CN112988362B (en) Task processing method and device, electronic equipment and storage medium
CN108733496B (en) Event processing method and device
CN107423128B (en) Information processing method and system
CN110377440B (en) Information processing method and device
CN110716848A (en) Data collection method and device, electronic equipment and storage medium
CN113259744B (en) Video display method, device, equipment and medium
EP3242197A1 (en) Desktop sharing method and mobile terminal
EP3506599A1 (en) Method for synchronizing contact information, apparatus, medium, electronic device and system
CN111694629A (en) Information display method and device and electronic equipment
CN111008032A (en) Page data updating method and device
CN108764866B (en) Method and equipment for allocating resources and drawing resources
CN102333280A (en) Business secret key renewing method and system and business processing server
CN114546588A (en) Task deployment method and device, storage medium and electronic device
CN112685104A (en) Application program starting control method and device, electronic equipment and storage medium
CN112671816B (en) File downloading method, device, equipment and medium
CN110704760B (en) Data processing method and device
CN110795328A (en) Interface testing method and device
CN106933449B (en) Icon processing method and device
CN110266526B (en) Equipment tree loading method and equipment
CN114564249A (en) Recommendation scheduling engine, recommendation scheduling method, and computer-readable storage medium
US9509772B1 (en) Visualization and control of ongoing ingress actions
CN110324370B (en) Method and device for pushing data to client by server
CN113572704A (en) Information processing method, production end, consumption end and server
CN113407331A (en) Task processing method and device and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40041934

Country of ref document: HK

SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant