CN107450971B - Task processing method and device - Google Patents

Task processing method and device Download PDF

Info

Publication number
CN107450971B
CN107450971B CN201710517218.8A CN201710517218A CN107450971B CN 107450971 B CN107450971 B CN 107450971B CN 201710517218 A CN201710517218 A CN 201710517218A CN 107450971 B CN107450971 B CN 107450971B
Authority
CN
China
Prior art keywords
task
processed
queue
processing
thread
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
CN201710517218.8A
Other languages
Chinese (zh)
Other versions
CN107450971A (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.)
Beijing 58 Information Technology Co Ltd
Original Assignee
Beijing 58 Information 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 Beijing 58 Information Technology Co Ltd filed Critical Beijing 58 Information Technology Co Ltd
Priority to CN201710517218.8A priority Critical patent/CN107450971B/en
Publication of CN107450971A publication Critical patent/CN107450971A/en
Application granted granted Critical
Publication of CN107450971B publication Critical patent/CN107450971B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/5038Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5011Pool
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5018Thread allocation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/548Queue

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the invention provides a task processing method and a task processing device, wherein the method comprises the following steps: acquiring a task to be processed generated by the application program and the type of the task to be processed; determining a target queue in a queue set according to the type of the task to be processed, wherein the queue set comprises a plurality of queues; caching the task to be processed to the target queue; and after the previous task of the task to be processed in the target queue is determined to be processed, processing the task to be processed through threads in a thread pool, wherein the number of the threads in the thread pool is smaller than that of the queues in the queue set. The method is used for avoiding the problem that the application program is abnormal due to the fact that the number of threads running in parallel is too large.

Description

Task processing method and device
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a task processing method and device.
Background
In an application program (software), there are many time-consuming service logics, for example, data of a server is acquired, configuration information is stored, log information is reported at regular time, and in order to ensure normal operation of the application program, the time-consuming service logics can be implemented by an IntentService class (service component).
In the running process of the application program, when the application program runs to a preset node, the application program can instantiate the corresponding business logic to obtain an instantiated task in order to realize a preset function, and the instantiated task is used for completing the corresponding function. Each business logic is used for realizing a function, the instantiated tasks can realize the functions provided by the business logic, and the instantiated tasks can also have custom functions. When the application program runs to different nodes, different instantiations can be performed on the same business logic to obtain a plurality of tasks, and the plurality of tasks can all realize the functions provided by the business logic, but the plurality of tasks may have different custom functions, wherein the plurality of tasks obtained by instantiating one business logic are executed in series, and the plurality of tasks obtained by instantiating different business logics can be executed in parallel.
In the prior art, after a business logic is instantiated to obtain a task, a thread corresponding to the task is created through a service component, and the task is executed through the thread. However, when the number of instantiated tasks is large, multiple threads need to be created, and when the number of threads is large, the application program may be abnormally operated.
Disclosure of Invention
The embodiment of the invention provides a task processing method and a task processing device, which solve the problem of abnormity of an application program caused by too many threads running in parallel.
In a first aspect, an embodiment of the present invention provides a task processing method, including:
acquiring a task to be processed generated by the application program and the type of the task to be processed;
determining a target queue in a queue set according to the type of the task to be processed, wherein the queue set comprises a plurality of queues;
caching the task to be processed to the target queue;
and after the previous task of the task to be processed in the target queue is determined to be processed, processing the task to be processed through threads in a thread pool, wherein the number of the threads in the thread pool is smaller than that of the queues in the queue set.
In a possible implementation manner, the processing, by a thread in a thread pool, the to-be-processed task after determining that processing of a previous task of the to-be-processed task in the target queue is completed includes:
acquiring a processing completion message corresponding to a task before the task to be processed in the target queue;
and processing the task to be processed through the thread in the thread pool according to the processing completion message.
In another possible implementation manner, the processing the to-be-processed task through a thread in the thread pool according to the processing completion message includes:
storing the task to be processed to a cache queue corresponding to the thread pool according to the processing completion message;
and when the task to be processed is determined to be located at the head of the cache queue and an idle thread exists in the thread pool, processing the task to be processed through the idle thread.
In another possible implementation manner, before storing the to-be-processed task to the cache queue corresponding to the thread pool according to the processing completion message, the method further includes:
after determining that the application program is started, creating the cache queue;
and when determining that the first task exists in the queues in the queue set, storing the first task in each queue to the buffer queue.
In another possible implementation manner, after storing the to-be-processed task to the cache queue corresponding to the thread pool according to the processing completion message, the method further includes:
and moving the task to be processed out of the target queue.
In another possible implementation manner, after the idle thread processes the task to be processed, the method further includes:
and moving the task to be processed out of the cache queue.
In a second aspect, an embodiment of the present invention provides a task processing apparatus, including an obtaining module, a determining module, a storing module, and a processing module, where,
the acquisition module is used for acquiring the tasks to be processed generated by the application program and the types of the tasks to be processed;
the determining module is used for determining a target queue in a queue set according to the type of the task to be processed, wherein the queue set comprises a plurality of queues;
the storage module is used for caching the task to be processed to the target queue;
and the processing module is used for processing the task to be processed through threads in a thread pool after the previous task in the target queue is determined to be processed, wherein the number of the threads in the thread pool is smaller than that of the queues in the queue set.
In one possible embodiment, the processing module comprises an acquisition unit and a processing unit, wherein,
the acquiring unit is used for acquiring a processing completion message corresponding to a task before the task to be processed in the target queue;
and the processing unit is used for processing the task to be processed through the thread in the thread pool according to the processing completion message.
In another possible implementation, the processing unit is specifically configured to:
storing the task to be processed to a cache queue corresponding to the thread pool according to the processing completion message;
and when the task to be processed is determined to be located at the head of the cache queue and an idle thread exists in the thread pool, processing the task to be processed through the idle thread.
In another possible embodiment, the apparatus further comprises a creation module, wherein,
the creating module is configured to create the cache queue after determining that the application program is started before the processing unit stores the to-be-processed task to the cache queue corresponding to the thread pool according to the processing completion message;
the storage module is further configured to store the first task in each queue to the cache queue when it is determined that the first task exists in the queue set.
In another possible implementation, the storage module is further configured to:
and after the processing unit stores the task to be processed to the cache queue corresponding to the thread pool according to the processing completion message, removing the task to be processed from the target queue.
In another possible implementation, the storage module is further configured to:
and after the processing unit processes the task to be processed through the idle thread, removing the task to be processed from the cache queue.
According to the task processing method and device provided by the embodiment of the invention, after the application program instantiates the task to be processed, the reconstruction service assembly obtains the type of the task to be processed, determines the target queue for caching the task to be processed according to the type of the task to be processed, and caches the task to be processed to the target queue. The reconfiguration service component performs thread processing on the tasks in one queue through the threads in the shared thread pool, and performs parallel processing on the tasks in different queues until the reconfiguration service component determines that the previous task of the task to be processed in the target queue is processed and completed, and then the reconfiguration service component processes the task to be processed through the threads in the thread pool, so that the tasks in the same queue are processed in series, and the tasks in different queues are processed in parallel.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
Fig. 1 is a schematic view of an application scenario of a task processing method according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a task processing method according to an embodiment of the present invention;
fig. 3 is a schematic flowchart of a method for processing a task to be processed according to an embodiment of the present invention;
FIG. 4 is a diagram illustrating a queue structure according to an embodiment of the present invention;
FIG. 5 is a first schematic structural diagram of a task processing device according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of a task processing device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, 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 some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a schematic view of an application scenario of a task processing method according to an embodiment of the present invention. Referring to fig. 1, an application installed in a terminal device includes a plurality of service logics and a reconfiguration service component, each service logic is used to implement a function, the service logics shown in the present application are time-consuming service logics, and tasks obtained by instantiating the service logics shown in the present application need to be implemented by the reconfiguration service component. In the process of running the application program in the terminal equipment, the application program instantiates the business logic to obtain tasks corresponding to the business logic, wherein one business logic can be instantiated to obtain a plurality of tasks, and after the instantiated tasks are obtained, the tasks are run in the background through reconstructing the service assembly.
Specifically, after the reconfiguration service component acquires a task which needs to run in the background, the reconfiguration service component places the task in a corresponding queue according to the type of the task and controls threads in a thread pool to process the tasks in each queue, wherein the threads in the thread pool need to process the tasks in one queue in series and process the tasks in different queues in parallel. In the application, the execution flow of the reconfiguration service assembly is improved, so that the reconfiguration service assembly can serially process the tasks of the same type and parallelly process the tasks of different types, and the reconfiguration service assembly processes the tasks through the threads in the thread pool, so that the number of the threads in the thread pool can be preset, and further, the abnormal operation of an application program can be avoided.
The technical means shown in the present application will be described in detail below with reference to specific examples. It should be noted that the following embodiments may be combined with each other, and the same or similar contents are not described in detail in different embodiments.
Fig. 2 is a flowchart illustrating a task processing method according to an embodiment of the present invention. Referring to fig. 2, the method may include:
s201, a task to be processed generated by the application program and the type of the task to be processed are obtained.
The execution main body of the embodiment of the present invention may be a task processing device, and the task processing device may be a reconfiguration service component in an application program, for example, the reconfiguration service component may be a BatchIntentService, and the reconfiguration service component may be an improvement on an existing service component IntentService. It should be noted that, in the following description, a task processing device is taken as an example of a reconfiguration service component. Alternatively, the reconstitution service component may be implemented in software.
It should be noted that, in the embodiment of the present invention, the processing procedure of the reconfiguration service component on any one task is the same, and in the embodiment of the present invention, the processing procedure of the reconfiguration service component on any one task to be processed is taken as an example for description.
The application program shown in the embodiment of the present invention may be any application program installed in a device such as a mobile phone and a computer. The application program comprises a plurality of service logics, the application program can call the service logics to realize corresponding functions in the running process of the application program, the service logics are instantiated when the application program calls the service logics to obtain instantiated tasks to be processed, the reconstruction service assembly is called to process the tasks to be processed, and optionally, the tasks to be processed can be transmitted to the reconstruction service assembly so that the reconstruction service assembly can obtain the tasks to be processed.
In the embodiment of the present invention, the type of the task to be processed may be represented by a service logic corresponding to the task to be processed, where the service logic may include "acquiring data of a server", "storing configuration information", "reporting log information at regular time", and the like. The types of the multiple tasks to be processed obtained by the same service logic instantiation are the same, and the types of the multiple tasks to be processed obtained by different service logic instantiations are different.
Optionally, the reconfiguration service component may obtain a service logic corresponding to the task to be processed, and determine the type of the task to be processed according to the service logic corresponding to the task to be processed.
S202, determining a target queue in a queue set according to the type of the task to be processed, wherein the queue set comprises a plurality of queues.
Optionally, the queues in the queue set may be created in the memory of the terminal device after the application is started. The queue set comprises a plurality of queues, and each queue corresponds to one task type.
After the reconstruction service assembly obtains the type of the task to be processed, determining a target queue corresponding to the type of the task to be processed in the queue combination according to the type of the task to be processed.
And S203, caching the tasks to be processed to a target queue.
In the embodiment of the invention, each queue in the queue set is a first-in first-out queue, so that the task to be processed is cached to the tail of the target queue.
And S204, processing the task to be processed through the thread in the thread pool after the previous task in the target queue and the task to be processed is determined to be processed.
The thread pool includes a plurality of threads, the threads in the thread pool may be created after the application program is started, the plurality of threads may process the task in each queue in the queue set, and optionally, the number of threads in the thread pool is generally smaller than the number of queues in the queue set. The threads in the thread pool need to serially process the tasks in one queue, that is, for one queue, only after one task in the queue is processed, the next task in the queue can be processed. The threads in the thread pool can process the tasks in different queues in parallel, that is, the tasks in different queues can be processed simultaneously by different threads in the thread pool.
Because tasks in one queue need to be processed serially, for any one queue, after the reconfiguration service component determines that processing of one task in the queue is completed, the reconfiguration service component will deliver the next task to be processed in the queue to a thread in the thread pool for processing.
Correspondingly, after the reconfiguration service component caches the task to be processed to the target queue, the reconfiguration service component processes the task to be processed through the thread in the thread pool after determining that the previous task of the task to be processed in the target queue is processed.
According to the task processing method provided by the embodiment of the invention, after the application program instantiates to obtain the task to be processed, the reconstruction service assembly obtains the type of the task to be processed, determines the target queue for caching the task to be processed according to the type of the task to be processed, and caches the task to be processed to the target queue. The reconfiguration service component performs thread processing on the tasks in one queue through the threads in the shared thread pool, and performs parallel processing on the tasks in different queues until the reconfiguration service component determines that the previous task of the task to be processed in the target queue is processed and completed, and then the reconfiguration service component processes the task to be processed through the threads in the thread pool, so that the tasks in the same queue are processed in series, and the tasks in different queues are processed in parallel.
Based on any of the above embodiments, optionally, the reconfiguration service component may process the to-be-processed task through the thread in the thread pool in the following feasible implementation manner (S204 in the embodiment shown in fig. 2), specifically, please refer to the embodiment shown in fig. 3.
Fig. 3 is a schematic flowchart of a method for processing a to-be-processed task according to an embodiment of the present invention. Referring to fig. 3, the method may include:
s301, a processing completion message corresponding to a task before the task to be processed in the target queue is obtained.
In the embodiment of the invention, after the thread completes the processing of one task, a processing completion message corresponding to the processing task is generated, and the processing completion message is fed back to the reconfiguration service component.
And S302, storing the task to be processed to a cache queue corresponding to the thread pool according to the processing completion message.
Optionally, after determining that the application is started, a buffer queue may be created in a memory of the terminal device in which the application is installed. And when determining that the first task exists in the queues in the queue set, storing the first task in each queue to a buffer queue.
Optionally, the first task in the queue refers to a task that is first buffered into the queue in the process after the application program is started, and each queue has a corresponding first task. Optionally, in the running process of the application program, it is determined whether a first task exists in each queue in the queue set, and when it is determined that the first task exists in the queue, the first task is stored in the buffer queue, and the first task is deleted from the queue.
And after the reconstruction service assembly obtains a processing completion message corresponding to a task before the task to be processed in the target queue, the reconstruction service assembly stores the task to be processed into a cache queue corresponding to the thread pool. The buffer queue is a first-in first-out queue, so that the reconfiguration service component stores the tasks to be processed to the tail of the buffer queue.
And S303, moving the task to be processed out of the target queue.
S304, when the task to be processed is determined to be located at the head of the cache queue and an idle thread exists in the thread pool, processing the task to be processed through the idle thread.
And optionally, when the reconfiguration service component determines that an idle thread exists in the thread pool, handing the task at the head of the cache queue over to the idle thread for processing, and simultaneously, removing the task handed over to the idle thread for processing from the cache queue.
And when the reconstruction service assembly determines that the task to be processed is positioned at the head of the cache queue and an idle thread exists in the thread pool, handing the task to be processed to the idle thread in the thread pool to process the task to be processed.
S305, moving the task to be processed out of the buffer queue.
After the task to be processed is processed by an idle thread in the thread pool, the reconstruction service component moves the task to be processed out of the cache queue.
In the embodiment shown in fig. 3, by setting the buffer queues corresponding to the thread pool, it can be ensured that the threads in the thread pool perform uniform processing on the tasks in each queue.
The technical solution shown in the above method embodiment is described in detail below by referring to a schematic diagram of a queue structure shown in fig. 4 through a specific example. Fig. 4 is a schematic diagram of a queue structure according to an embodiment of the present invention.
For example, it is assumed that 5 service logics, respectively denoted as service logic 1 to service logic 5, are included in the application program. Assume again that the thread pool includes 3 threads, denoted as thread 1-thread 3, respectively.
After the application program is started in the terminal device, a queue corresponding to each service logic is created in the memory of the terminal device and is respectively recorded as a queue 1-a queue 5, and a cache queue corresponding to the thread pool is also created in the memory of the terminal device and is recorded as a cache queue 1.
During the running of the application program, the application program may instantiate the business logic 1-business logic 5, assuming that after the application program is started, the business logic 1-business logic 5 is instantiated to obtain a plurality of tasks, each task being stored in a corresponding queue, assuming that the tasks stored in each queue are as shown in 401 in fig. 4.
Referring to 401, initially, tasks 11-13 are included in queue 1, tasks 21-22 are included in queue 2, tasks 31 are included in queue 3, and tasks 51-53 are included in queue 5, and no tasks are included in the buffer queue.
Assume that the first task in queue 1 is task 11, the first task in queue 2 is task 21, the first task in queue 3 is task 31, and the first task in queue 5 is task 51. After determining the first task in the queue, each first task is stored in the buffer queue 1, and the first task is deleted in the corresponding queue, at this time, the task stored in each queue is shown as 402 in fig. 4.
Referring to 402, the first task in queues 1-5 is transferred to buffer queue 1.
The restructuring service component delivers the tasks 11-31 in the buffer queues to the threads 1-3 for processing, and at this time, the tasks stored in each queue and the tasks currently processed by each thread are shown as 403 in fig. 4.
After the thread 1 finishes processing the task 11, generating a processing completion message 1 corresponding to the task 11, after the reconfiguration service component acquires the processing completion message 1, the reconfiguration service component stores the task 12 at the head of the queue 1 in the cache queue 1, and deletes the task 12 in the queue 1, and meanwhile, because the task 51 is located at the head of the cache queue 1 and an idle thread (thread 1) exists in the thread pool, the task 51 is handed over to the thread 1 for processing, at this time, the task stored in each queue and the task currently processed by each thread are as shown in 404 in fig. 4.
And so on until all the tasks in queues 1-5 are processed. It should be noted that, in the process of processing the tasks in the queues 1 to 5, new tasks may also be added in the queues 1 to 5, and the processing process of the new tasks is similar to the above process and is not described again here.
In the above process, if according to the method in the prior art, at most 5 threads need to be created, and 5 threads run in parallel, in the present application, at most 3 threads run in parallel, which avoids the problem of abnormal occurrence of the application program due to too many threads running in parallel.
Fig. 5 is a first schematic structural diagram of a task processing device according to an embodiment of the present invention. Referring to fig. 5, the apparatus may include an obtaining module 11, a determining module 12, a storing module 13 and a processing module 14, wherein,
the obtaining module 11 is configured to obtain a to-be-processed task generated by the application program and a type of the to-be-processed task;
the determining module 12 is configured to determine a target queue in a queue set according to the type of the task to be processed, where the queue set includes a plurality of queues;
the storage module 13 is configured to cache the to-be-processed task to the target queue;
the processing module 14 is configured to, after it is determined that processing of a previous task of the to-be-processed task in the target queue is completed, process the to-be-processed task through threads in a thread pool, where the number of threads in the thread pool is smaller than the number of queues in the queue set.
The task processing device provided in the embodiment of the present invention may execute the technical solutions shown in the above method embodiments, and the implementation principles and beneficial effects thereof are similar, and are not described herein again.
Fig. 6 is a schematic structural diagram of a task processing device according to an embodiment of the present invention. On the basis of the embodiment shown in fig. 5, referring to fig. 6, the processing module 14 includes an obtaining unit 141 and a processing unit 142, wherein,
the obtaining unit 141 is configured to obtain a processing completion message corresponding to a task before the to-be-processed task in the target queue;
the processing unit 142 is configured to process the to-be-processed task through a thread in the thread pool according to the processing completion message.
In a possible implementation, the processing unit 142 is specifically configured to:
storing the task to be processed to a cache queue corresponding to the thread pool according to the processing completion message;
and when the task to be processed is determined to be located at the head of the cache queue and an idle thread exists in the thread pool, processing the task to be processed through the idle thread.
In another possible embodiment, the apparatus further comprises a creation module 15, wherein,
the creating module 15 is configured to create the cache queue after determining that the application program is started before the processing unit 142 stores the to-be-processed task to the cache queue corresponding to the thread pool according to the processing completion message;
the storage module 13 is further configured to store the first task in each queue to the cache queue when it is determined that the first task exists in the queue set.
In another possible embodiment, the storage module 13 is further configured to:
after the processing unit 142 stores the to-be-processed task to the cache queue corresponding to the thread pool according to the processing completion message, the to-be-processed task is moved out of the target queue.
In another possible embodiment, the storage module 13 is further configured to:
after the processing unit 142 processes the task to be processed through the idle thread, the task to be processed is moved out of the cache queue.
The task processing device provided in the embodiment of the present invention may execute the technical solutions shown in the above method embodiments, and the implementation principles and beneficial effects thereof are similar, and are not described herein again.
Those of ordinary skill in the art will understand that: all or a portion of the steps of implementing the above-described method embodiments may be performed by hardware associated with program instructions. The program may be stored in a computer-readable storage medium. When executed, the program performs steps comprising the method embodiments described above; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
Finally, it should be noted that: the above embodiments are only used for illustrating the technical solutions of the embodiments of the present invention, and are not limited thereto; although embodiments of the present invention have been described in detail with reference to the foregoing embodiments, those skilled in the art will understand that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the embodiments of the present invention.

Claims (8)

1. A task processing method, comprising:
acquiring a task to be processed generated by an application program and the type of the task to be processed;
determining a target queue in a queue set according to the type of the task to be processed, wherein the queue set comprises a plurality of queues;
caching the task to be processed to the target queue;
after the previous task of the task to be processed in the target queue is determined to be processed, processing the task to be processed through threads in a thread pool, wherein the number of the threads in the thread pool is smaller than that of the queues in the queue set;
after determining that processing of a previous task of the to-be-processed task in the target queue is completed, processing the to-be-processed task through a thread in a thread pool includes:
acquiring a processing completion message corresponding to a task before the task to be processed in the target queue;
processing the task to be processed through the thread in the thread pool according to the processing completion message;
the processing the task to be processed through the thread in the thread pool according to the processing completion message includes:
storing the task to be processed to a cache queue corresponding to the thread pool according to the processing completion message;
and when the task to be processed is determined to be located at the head of the cache queue and an idle thread exists in the thread pool, processing the task to be processed through the idle thread.
2. The method according to claim 1, wherein before storing the to-be-processed task to the cache queue corresponding to the thread pool according to the processing completion message, the method further comprises:
after determining that the application program is started, creating the cache queue;
and when determining that the first task exists in the queues in the queue set, storing the first task in each queue to the buffer queue.
3. The method according to claim 1 or 2, wherein after storing the to-be-processed task to the cache queue corresponding to the thread pool according to the processing completion message, the method further comprises:
and moving the task to be processed out of the target queue.
4. The method according to claim 1 or 2, wherein after the idle thread processes the task to be processed, the method further comprises:
and moving the task to be processed out of the cache queue.
5. A task processing device is characterized by comprising an acquisition module, a determination module, a storage module and a processing module, wherein,
the acquisition module is used for acquiring the tasks to be processed generated by the application program and the types of the tasks to be processed;
the determining module is used for determining a target queue in a queue set according to the type of the task to be processed, wherein the queue set comprises a plurality of queues;
the storage module is used for caching the task to be processed to the target queue;
the processing module is used for processing the task to be processed through threads in a thread pool after the previous task in the target queue and the task to be processed are determined to be processed, wherein the number of the threads in the thread pool is smaller than that of the queues in the queue set;
the processing module comprises an acquisition unit and a processing unit, wherein,
the acquiring unit is used for acquiring a processing completion message corresponding to a task before the task to be processed in the target queue;
the processing unit is used for processing the task to be processed through the thread in the thread pool according to the processing completion message;
the processing unit is specifically configured to:
storing the task to be processed to a cache queue corresponding to the thread pool according to the processing completion message;
and when the task to be processed is determined to be located at the head of the cache queue and an idle thread exists in the thread pool, processing the task to be processed through the idle thread.
6. The apparatus of claim 5, further comprising a creation module, wherein,
the creating module is configured to create the cache queue after determining that the application program is started before the processing unit stores the to-be-processed task to the cache queue corresponding to the thread pool according to the processing completion message;
the storage module is further configured to store the first task in each queue to the cache queue when it is determined that the first task exists in the queue set.
7. The apparatus of claim 5 or 6, wherein the storage module is further configured to:
and after the processing unit stores the task to be processed to the cache queue corresponding to the thread pool according to the processing completion message, removing the task to be processed from the target queue.
8. The apparatus of claim 5 or 6, wherein the storage module is further configured to:
and after the processing unit processes the task to be processed through the idle thread, removing the task to be processed from the cache queue.
CN201710517218.8A 2017-06-29 2017-06-29 Task processing method and device Active CN107450971B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710517218.8A CN107450971B (en) 2017-06-29 2017-06-29 Task processing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710517218.8A CN107450971B (en) 2017-06-29 2017-06-29 Task processing method and device

Publications (2)

Publication Number Publication Date
CN107450971A CN107450971A (en) 2017-12-08
CN107450971B true CN107450971B (en) 2021-01-29

Family

ID=60488527

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710517218.8A Active CN107450971B (en) 2017-06-29 2017-06-29 Task processing method and device

Country Status (1)

Country Link
CN (1) CN107450971B (en)

Families Citing this family (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108228354B (en) * 2017-12-29 2022-03-18 杭州朗和科技有限公司 Scheduling method, system, computer device and medium
CN109343941B (en) * 2018-08-14 2023-02-21 创新先进技术有限公司 Task processing method and device, electronic equipment and computer readable storage medium
CN111355673A (en) * 2018-12-24 2020-06-30 深圳市中兴微电子技术有限公司 Data processing method, device, equipment and storage medium
CN111381976B (en) * 2018-12-28 2023-08-04 广州市百果园信息技术有限公司 Method and device for updating message prompt data, storage medium and computer equipment
CN110765167B (en) * 2019-10-23 2022-07-22 泰康保险集团股份有限公司 Policy data processing method, policy data processing device and policy data processing equipment
CN110928905B (en) * 2019-11-07 2024-01-26 泰康保险集团股份有限公司 Data processing method and device
CN111190751B (en) * 2019-12-30 2023-12-08 广州酷狗计算机科技有限公司 Task processing method and device based on song list, computer equipment and storage medium
CN113313600B (en) * 2020-02-26 2024-05-17 京东科技控股股份有限公司 Message processing method, device and system, storage medium and electronic device
CN113360254A (en) * 2020-03-06 2021-09-07 北京搜狗科技发展有限公司 Task scheduling method and system
CN111736976B (en) * 2020-06-30 2023-08-15 中国工商银行股份有限公司 Task processing method, device, computing equipment and medium
CN111858046B (en) * 2020-07-13 2024-05-24 海尔优家智能科技(北京)有限公司 Service request processing method and device, storage medium and electronic device
CN112817745A (en) * 2021-01-14 2021-05-18 内蒙古蒙商消费金融股份有限公司 Task processing method and device
CN112711490B (en) * 2021-03-26 2021-07-16 统信软件技术有限公司 Message processing method, computing device and storage medium
CN113905273B (en) * 2021-09-29 2024-05-17 上海阵量智能科技有限公司 Task execution method and device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101702784A (en) * 2009-11-18 2010-05-05 上海市共进通信技术有限公司 Multitask communication system and method of optical access multiuser residential unit embedded device
CN102722417A (en) * 2012-06-07 2012-10-10 腾讯科技(深圳)有限公司 Distribution method and device for scan task
CN103166845A (en) * 2013-03-01 2013-06-19 华为技术有限公司 Data processing method and device
CN106325980A (en) * 2015-06-30 2017-01-11 中国石油化工股份有限公司 Multi-thread concurrent system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101702784A (en) * 2009-11-18 2010-05-05 上海市共进通信技术有限公司 Multitask communication system and method of optical access multiuser residential unit embedded device
CN102722417A (en) * 2012-06-07 2012-10-10 腾讯科技(深圳)有限公司 Distribution method and device for scan task
CN103166845A (en) * 2013-03-01 2013-06-19 华为技术有限公司 Data processing method and device
CN106325980A (en) * 2015-06-30 2017-01-11 中国石油化工股份有限公司 Multi-thread concurrent system

Also Published As

Publication number Publication date
CN107450971A (en) 2017-12-08

Similar Documents

Publication Publication Date Title
CN107450971B (en) Task processing method and device
US10042668B2 (en) Concurrent execution of a computer software application along multiple decision paths
US11941434B2 (en) Task processing method, processing apparatus, and computer system
CN107832100B (en) APK plug-in loading method and terminal thereof
US20200204650A1 (en) De-duplicating remote procedure calls
CN111782360A (en) Distributed task scheduling method and device
US20170047069A1 (en) Voice processing method and device
US10417062B2 (en) Method and apparatus of unloading out of memory processing flow to user space
US9727364B2 (en) Virtual device hypervisor memory limited receive queuing
WO2016045439A1 (en) Vnfm disaster-tolerant protection method and device, nfvo and storage medium
CN111026541B (en) Rendering resource scheduling method, device, equipment and storage medium
CN113568686B (en) Asynchronous processing method and device for Lua language, computer equipment and storage medium
CN110716848A (en) Data collection method and device, electronic equipment and storage medium
CN111200606A (en) Deep learning model task processing method, system, server and storage medium
US10318456B2 (en) Validation of correctness of interrupt triggers and delivery
CN110968410B (en) Task failure retry method and device, computer equipment and storage medium
CN111694645B (en) Task processing method and related device in distributed task scheduling system
US9658894B2 (en) Automatically and dynamically reclaiming resources during virtual machine decommission
CN110413398B (en) Task scheduling method and device, computer equipment and storage medium
CN108197029B (en) Method and device for acquiring process information
CN116366634A (en) File downloading method, device, terminal, source server and medium
US9766940B2 (en) Enabling dynamic job configuration in mapreduce
JP2018538632A (en) Method and device for processing data after node restart
CN115599507A (en) Data processing method, execution workstation, electronic device and storage medium
CN111159236A (en) Data processing method and device, electronic equipment and storage medium

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
GR01 Patent grant
GR01 Patent grant