CN107766137A - A kind of task processing method and device - Google Patents

A kind of task processing method and device Download PDF

Info

Publication number
CN107766137A
CN107766137A CN201710961495.8A CN201710961495A CN107766137A CN 107766137 A CN107766137 A CN 107766137A CN 201710961495 A CN201710961495 A CN 201710961495A CN 107766137 A CN107766137 A CN 107766137A
Authority
CN
China
Prior art keywords
sets
threads
task
tasks
thread pool
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201710961495.8A
Other languages
Chinese (zh)
Inventor
胡勇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke 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 Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201710961495.8A priority Critical patent/CN107766137A/en
Publication of CN107766137A publication Critical patent/CN107766137A/en
Pending legal-status Critical Current

Links

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
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
    • 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/4812Task transfer initiation or dispatching by interrupt, e.g. masked
    • 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
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5018Thread allocation

Abstract

The embodiment of the present invention provides a kind of task processing method and device, is related to field of computer technology.A kind of task processing method of the embodiment of the present invention, including:Create sets of threads thread pool;Calling task dispatching method, current pending set of tasks is passed in method for scheduling task;When sets of threads available free in sets of threads thread pool, set of tasks is passed to so that sets of threads performs set of tasks by sets of threads by method for scheduling task;When there is having not carried out for task in set of tasks, cancel having not carried out for task using Future;When there is being carrying out for task in set of tasks, cancel being carrying out for task using interrupt mechanism;Receive next pending set of tasks.Sets of threads thread pool existing for create in a manner of sets of threads of the embodiment of the present invention, set of tasks is performed by the sets of threads of free time so that sets of threads thread pool is after a set of tasks is received, moreover it is possible to performs other set of tasks and can cancel task.

Description

A kind of task processing method and device
Technical field
The present invention relates to computer realm, more particularly to a kind of task processing method and device.
Background technology
Prior art is when carrying out task processing, it is necessary to waits current task set to handle other after being finished Task.By taking Java technology as an example, as shown in Fig. 2 the general process for realizing task processing is:Based on JDK (Java Development Kit, the SDK of Java language) thread pool multiple tasks be encapsulated into one set in, so Calling task dispatching method afterwards, after completion condition (for example one of them is all completed or completed to all tasks) is reached, thread Chi Caineng continues executing with next task.The method for scheduling task is invokeAll methods or invokeAny methods, InvokeAll methods can realize the function of waiting all tasks all to complete, and invokeAny methods can realize wait wherein one The function that individual task is completed.
In process of the present invention is realized, inventor has found that at least there are the following problems in the prior art:
(1) after thread pool calls invokeAll methods or invokeAny methods, thread pool is waited for, no Other tasks can be handled, cause the wasting of resources.Such as:There are 10 threads to receive task in thread pool, appoint for incoming 3 now The set of business, it will be performed using 3 threads in thread pool.During waiting this 3 tasks to complete, remaining 7 Individual thread is in idle condition, from causing the wasting of resources.
(2) because thread pool will wait task to complete, therefore being carrying out or having not carried out for task can not be cancelled Fall.
The content of the invention
In view of this, the embodiment of the present invention provides a kind of task processing method and device.The embodiment of the present invention passes through establishment Sets of threads thread pool existing in a manner of sets of threads, set of tasks is specifically performed by the sets of threads of free time so that sets of threads line Cheng Chi is after a set of tasks is received, moreover it is possible to performs other set of tasks, is completed without waiting for all tasks carryings.When need When cancelling task, it is possible to cancel also being not carried out for task by Future Cancel methods, cancelled by interrupt mechanism Being carrying out for task..
To achieve the above object, a kind of one side according to embodiments of the present invention, there is provided task processing method.
A kind of task processing method of the embodiment of the present invention, including:Create sets of threads thread pool, the sets of threads thread pool Including multiple sets of threads, the sets of threads includes multiple threads;Calling task dispatching method, by current pending set of tasks It is passed in the method for scheduling task;When sets of threads available free in the sets of threads thread pool, pass through the task scheduling The set of tasks is passed to the sets of threads so that the sets of threads performs the set of tasks by method;When the set of tasks In when having having not carried out for task, using Future cancel described in the having not carried out of the task;Have when in the set of tasks During the task of execution, cancel being carrying out for the task using interrupt mechanism;Receive next pending set of tasks.
Alternatively, the sets of threads performs the set of tasks, including:Each task in the set of tasks is deposited It is placed in the task queue of the sets of threads;The method for scheduling task of the sets of threads is called, returns to the result pair of each task As.
Alternatively, methods described also includes:Call back function is passed in the method for scheduling task and the sets of threads.
Alternatively, methods described also includes:Obtained using Get methods or the call back function from the result object The implementing result of the set of tasks.
Alternatively, methods described also includes:When the sets of threads and the thread that there is no the free time in the sets of threads thread pool Group thread pool task queue less than when, the set of tasks is stored in the task queue, it is described idle to wait Sets of threads performs the set of tasks;When the task queue of the sets of threads thread pool is expired, located using refusal strategy Reason.
To achieve the above object, a kind of another aspect according to embodiments of the present invention, there is provided Task Processing Unit.
A kind of Task Processing Unit of the embodiment of the present invention, including:Creation module, for creating sets of threads thread pool, institute Stating sets of threads thread pool includes multiple sets of threads, and the sets of threads includes multiple threads;Afferent module is called, for calling task Dispatching method, current pending set of tasks is passed in the method for scheduling task;Set of tasks afferent module, for working as It is by the method for scheduling task that the set of tasks is incoming described in the sets of threads thread pool during available free sets of threads Sets of threads is so that the sets of threads performs the set of tasks;Cancel module, for being had not carried out when in the set of tasks Task when, using Future cancel described in the having not carried out of the task;When having being carrying out for task in the set of tasks, Cancel being carrying out for the task using interrupt mechanism;Receiving module, for receiving next pending set of tasks.
Alternatively, set of tasks afferent module, it is additionally operable to:Each task in the set of tasks is stored in described In the task queue of sets of threads;The method for scheduling task of the sets of threads is called, returns to the result object of each task.
Alternatively, described device also includes:Call back function afferent module, for call back function to be passed into the task scheduling In method and the sets of threads.
Alternatively, described device also includes:Implementing result acquisition module, for using Get methods or call back function from The implementing result of the set of tasks is obtained in the result object.
Alternatively, described device also includes:Set of tasks storage module, for free when not being in the sets of threads thread pool Not busy sets of threads and the task queue of the sets of threads thread pool less than when, the set of tasks is stored in the task queue In, to wait the idle sets of threads to perform the set of tasks;Refuse tactful processing module, for when the sets of threads When the task queue of thread pool is expired, handled using refusal strategy.
To achieve the above object, another further aspect according to embodiments of the present invention, there is provided a kind of electronic equipment.
The a kind of electronic equipment of the embodiment of the present invention, including:One or more processors;Storage device, for storing one Individual or multiple programs, when one or more of programs are by one or more of computing devices so that one or more Individual processor realizes a kind of task processing method of the embodiment of the present invention.
To achieve the above object, a kind of another further aspect according to embodiments of the present invention, there is provided computer-readable medium.
A kind of computer-readable medium of the embodiment of the present invention, is stored thereon with computer program, and described program is processed Device realizes a kind of task processing method of the embodiment of the present invention when performing.
One embodiment in foregoing invention has the following advantages that or beneficial effect:Deposited creating in a manner of sets of threads Sets of threads thread pool, by free time sets of threads specifically perform set of tasks so that sets of threads thread pool receive one appoint After business set, moreover it is possible to perform other set of tasks, improve the utilization rate of sets of threads thread pool;By using Future's Cancel methods are cancelled having not carried out for task or are cancelled being carrying out for task using interrupt mechanism;Pass through call back function Mode obtains the implementing result of set of tasks, there is provided a kind of mode of new acquisition implementing result.
Further effect adds hereinafter in conjunction with embodiment possessed by above-mentioned non-usual optional mode With explanation.
Brief description of the drawings
Accompanying drawing is used to more fully understand the present invention, does not form inappropriate limitation of the present invention.Wherein:
Fig. 1 is the key step schematic diagram of task processing method according to embodiments of the present invention;
Fig. 2 is the main flow schematic diagram of the task processing method of prior art;
Fig. 3 is the flow of the task processing method according to embodiments of the present invention that implementing result is obtained by Future modes Figure;
Fig. 4 is the flow of the task processing method according to embodiments of the present invention that implementing result is obtained by call back function Figure;
Fig. 5 is the schematic diagram of the main modular of Task Processing Unit according to embodiments of the present invention;
Fig. 6 is that the embodiment of the present invention can apply to exemplary system architecture figure therein;
Fig. 7 is applied to realize the structural representation of the computer installation of the electronic equipment of the embodiment of the present invention.
Embodiment
The one exemplary embodiment of the present invention is explained below in conjunction with accompanying drawing, including the various of the embodiment of the present invention Details should think them only exemplary to help understanding.Therefore, those of ordinary skill in the art should recognize Arrive, various changes and modifications can be made to the embodiments described herein, without departing from scope and spirit of the present invention.Together Sample, for clarity and conciseness, the description to known function and structure is eliminated in following description.
The core of the task processing method of the embodiment of the present invention is embodied as:Sets of threads thread pool is only responsible for set of tasks to lose The sets of threads idle to one, set of tasks is specifically performed by the idle sets of threads, is then back to related to the sets of threads Future gathers.Realize through the above way asynchronous so that sets of threads thread pool can not have to the execution knot for being concerned about the sets of threads Fruit, it is possible to continue executing with other set of tasks.If necessary to handle Future set, than performing knot if desired for acquisition During fruit, then obtained from Future set;When needing to cancel the set of tasks, Future Cancel methods are called to cancel. It should be noted that this method can only cancel being carrying out or being also not carried out for task, it is impossible to cancel having completed for task.
Fig. 1 is the schematic diagram of the key step of task processing method according to embodiments of the present invention.As shown in figure 1, this hair The task processing method of bright embodiment, mainly comprises the following steps:
Step S101:Sets of threads thread pool is created, the sets of threads thread pool includes sets of threads pond, task queue and refusal Strategy, sets of threads pond include multiple sets of threads, and sets of threads includes JDK sets of threads, thread and task queue.The sets of threads thread pool Itself or a thread pool, the thread in thread pool is grouped, each corresponding sets of threads of packet, multiple sets of threads are formed Sets of threads pond, sets of threads pond, task queue and refusal strategy form sets of threads thread pool.Can be with when creating sets of threads thread pool The establishment process of JDK thread pools is simulated, for example is generated by constructor or JDK tool-class.Create after completing, it is necessary to initial Change the thread in the sets of threads thread pool.Initialization thread can be realized by init methods.
Step S102:Calling task dispatching method, current pending set of tasks is passed to the method for scheduling task In.The method for scheduling task of sets of threads thread pool can be invokeAll methods or invokeAny methods as desired, InvokeAll methods are used to wait all tasks carryings in set of tasks to complete, and return to Future set;invokeAny Method is used to wait a tasks carrying in set of tasks to complete, and returns to Future set.
Step S103:, will by the method for scheduling task when sets of threads available free in the sets of threads thread pool The set of tasks is passed to the sets of threads so that the sets of threads performs the set of tasks.Called in the embodiment of the present invention When invokeAll methods or invokeAny methods, judge in the sets of threads thread pool whether available free sets of threads, such as The available free sets of threads of fruit, then set of tasks is performed using the sets of threads, and return to Future set;If without the free time Sets of threads, then set of tasks is put into the task queue of sets of threads thread pool, waits idle sets of threads to perform task-set Close;If the task queue of sets of threads thread pool is full, also set of tasks is toward adding in sets of threads thread pool, then using refusal Strategy is handled.
Step S104:When having having not carried out for task in the set of tasks, not yet held using described in Future cancellations Capable task;When having being carrying out for task in the set of tasks, cancel using interrupt mechanism described be carrying out Task.Because the sets of threads thread pool is after a set of tasks is received, completed without waiting for all tasks carryings, so that it may To perform other set of tasks.Therefore, when needing cancellation task, it can be cancelled by Future Cancel methods and not yet held Capable task, cancel being carrying out for task using interrupt mechanism.
Step S105:Receive next pending set of tasks.Afterwards, next pending set of tasks is updated For current pending set of tasks, step S102 is performed.
Fig. 3 is the flow of the task processing method according to embodiments of the present invention that implementing result is obtained by Future modes Figure.Future is a kind of design pattern in Java, represents the result that current tasks carrying will obtain after completing.Task quilt After thread pool scheduling, a Future result object can be returned in real time, is sometime thinking the execution of acquisition task in the future When as a result, it can be obtained from the Future result objects.As shown in figure 3, the task processing method of the embodiment of the present invention, including Following steps:
(1) sets of threads thread pool is created, initializes the thread in the sets of threads thread pool.The sets of threads thread pool bag Sets of threads pond, task queue and refusal strategy are included, sets of threads pond includes multiple sets of threads, and sets of threads includes JDK sets of threads, thread And task queue.
(2) calling task dispatching method, current pending set of tasks is passed in the method for scheduling task.Thread The method for scheduling task of group thread pool can be invokeAll methods or invokeAny methods as desired, invokeAll Method is asynchronous call, for waiting all tasks carryings in set of tasks to complete, and returns to Future set; InvokeAny methods are also asynchronous call, for waiting a tasks carrying in set of tasks to complete, and are returned Future gathers.
(3) judge in the sets of threads thread pool whether available free sets of threads, when available free sets of threads, perform (4);When no idle sets of threads, perform (5).
(4) an idle sets of threads is selected, current pending set of tasks is passed in the sets of threads so that described Sets of threads performs the set of tasks, and returns to Future set.Performed when sets of threads thread pool calling task dispatching method During set of tasks, set of tasks is really transferred to sets of threads to perform, specific implementation procedure is:
The method for scheduling task of (4a) receiving thread group thread pool is transmitted through the set of tasks come, each in set of tasks Task is all stored in the task queue of sets of threads.
(4b) calls the method for scheduling task of sets of threads, returns to Future set.The method for scheduling task method is by following Ring calls Execute methods to perform each task, and the Future results pair of each task of the result for returning to the task of execution As Future result objects form Future set.The method for scheduling task of sets of threads can be invokeAll methods or InvokeAny methods, invokeAll methods are synchronization calls, for waiting all tasks carryings in set of tasks to complete, and Return to the Future set of all having performed for tasks;InvokeAny methods are also synchronization call, for waiting in set of tasks A tasks carrying complete, and return having performed for task Future gather.Execute methods are asynchronous methods, It is the actuator of a specific tasks, for returning to Future result objects.Caller can gather all Future slow After depositing, uniformly process.
(5) judge whether the task queue of the sets of threads thread pool is full, if less than by current pending times Business set deposit task queue, wait the sets of threads of free time;If full, refusal strategy processing is used.Here refusal plan 4 kinds of JDK thread pools refusal strategies can be slightly simulated, wherein comprising throw exception strategy, directly being run in caller thread Current task, discarding nothing quietly are submitted in task, one will being performed for task of discarding and the trial being currently dropped again The task of method processing, not any processing.
(6) the sets of threads thread pool continues to next pending set of tasks, and next pending is appointed Business set is updated to current pending set of tasks, is transferred to (2).
In addition, if needing to handle Future set, for example obtain implementing result or cancel task, then it is right Single Future processing in Future set.Concrete processing procedure is:
Obtain implementing result:Set of tasks is obtained from the Future single Future gathered by Future Get methods Implementing result.If it is intended to obtaining real task action result, can be obtained by Future Get methods, Get side Method is synchronous method, and the implementing result of task is obtained by the mode of blocking, if task is also not carried out completing, calls Get methods, It can then block.
Cancellation task:Being had not carried out in set of tasks for task is cancelled by Future Cancel methods, or tasted Being carrying out in set of tasks for task is cancelled in examination using interrupt mechanism.Cancel methods are asynchronous method, for cancelling not yet Perform or attempt to cancel being carrying out for task.The interrupt mechanism of thread is called, it is necessary to perform one in sets of threads thread pool In the code of set of tasks, there is provided the processing to abnormal interruption, so as to which interrupt mechanism can be responded.It is certain that interruption is not offered as task It can be cancelled, the place that abnormal interruption responds if the task code being currently running has been passed by, then interrupt operation will not rise Effect.
Fig. 4 is the flow of the task processing method according to embodiments of the present invention that implementing result is obtained by call back function Figure.This method without Future, therefore can not cancel task as a result of call back function.As shown in figure 4, the present invention is implemented The task processing method of example, comprises the following steps:
(1) sets of threads thread pool is created, initializes the thread in the sets of threads thread pool.The sets of threads thread pool bag Sets of threads pond, task queue and refusal strategy are included, sets of threads pond includes multiple sets of threads, and sets of threads includes JDK sets of threads, thread And task queue.
(2) calling task dispatching method, current pending set of tasks and call back function are passed to the task scheduling In method.The method for scheduling task of sets of threads thread pool can be invokeAll methods or invokeAny side as desired Method.After set of tasks performs completion, call back function is called to notify the implementing result of the sets of threads thread pool set of tasks.
(3) judge in the sets of threads thread pool whether available free sets of threads, when available free sets of threads, perform (4);When no idle sets of threads, perform (5).
(4) an idle sets of threads is selected, current pending set of tasks is passed in the sets of threads so that described Sets of threads performs the set of tasks, and returns to Future set.Each Future result objects in Future set It is to have completed task.When sets of threads thread pool calling task dispatching method is to perform set of tasks, really task Set intersection is performed by sets of threads, and specific implementation procedure is:
The method for scheduling task of (4a) receiving thread group thread pool be transmitted through come set of tasks and call back function, then appoint Each task in business set is stored in the task queue of sets of threads.
(4b) calls the method for scheduling task of sets of threads, returns to Future set.The method for scheduling task method is by following Ring calls Execute methods to perform each task, and the Future results pair of each task of the result for returning to the task of execution As Future result objects form Future set.If necessary to obtain task result, then tied using Get methods from Future Fruit object acquisition, because Future result objects now are all tasks of having completed, no longer block the execution of thread.If The result for meeting invokeAll methods or invokeAny methods returns to condition, then call back function is called, so as to notify thread The implementing result of group thread pool task.The result of invokeAll methods returns to condition:All tasks in set of tasks all into Work(performs, and exception does not occur.The result of invokeAny methods returns to condition:There is a Mission Success to hold in set of tasks OK.
(5) judge whether the task queue of the sets of threads thread pool is full, if less than by current pending times Business set deposit task queue, wait the sets of threads of free time;If full, refusal strategy processing is used.
(6) the sets of threads thread pool continues to next pending set of tasks, and next pending is appointed Business set is updated to current pending set of tasks, is transferred to (2).If necessary to be entered according to the implementing result of current task set The execution of row follow-up work set, the follow-up method to be performed can be put into call back function.
It is can be seen that the task processing method of the embodiment of the present invention by line existing for creating in a manner of sets of threads Journey group thread pool, set of tasks is specifically performed by the sets of threads of free time so that sets of threads thread pool is receiving a set of tasks Afterwards, moreover it is possible to perform other set of tasks, improve the utilization rate of sets of threads thread pool;By using Future Cancel methods Cancel having not carried out for task or cancel being carrying out for task using interrupt mechanism;Obtained and appointed by way of call back function A kind of implementing result of business set, there is provided mode of new acquisition implementing result.
Fig. 5 is the schematic diagram of the main modular of Task Processing Unit according to embodiments of the present invention.As shown in figure 5, this hair The Task Processing Unit 500 of bright embodiment, mainly includes:
Creation module 501, for creating sets of threads thread pool, the sets of threads thread pool includes sets of threads pond, task team Row and refusal strategy, sets of threads pond include multiple sets of threads, and sets of threads includes JDK sets of threads, thread and task queue.
Afferent module 502 is called, for calling task dispatching method, current pending set of tasks is passed to described appoint It is engaged in dispatching method.The method for scheduling task of sets of threads thread pool can be as desired invokeAll methods or InvokeAny methods.
Set of tasks afferent module 503, for when sets of threads available free in the sets of threads thread pool, by described The set of tasks is passed to the sets of threads so that the sets of threads performs the set of tasks by method for scheduling task.Calling When invokeAll methods or invokeAny methods, judge in the sets of threads thread pool whether available free sets of threads, such as The available free sets of threads of fruit, then set of tasks is performed using the sets of threads, and return to Future set;If without the free time Sets of threads, then set of tasks is put into the task queue of sets of threads thread pool, waits idle sets of threads to perform task-set Close;If the task queue of sets of threads thread pool is full, also set of tasks is toward adding in sets of threads thread pool, then using refusal Strategy is handled.
Cancel module 504, for when having having not carried out for task in the set of tasks, cancelled using Future described in Having not carried out for task;When having being carrying out for task in the set of tasks, cancelled using interrupt mechanism it is described The task of execution.
Receiving module 505, for receiving next pending set of tasks.By next pending set of tasks more New is current pending set of tasks, continues calling task dispatching method to handle the set of tasks.
In addition, the Task Processing Unit of the embodiment of the present invention can also include (in following module maps not showing with lower module Go out):Call back function afferent module, for call back function to be passed in the method for scheduling task and the sets of threads.Perform knot Fruit acquisition module, for obtaining the execution of the set of tasks from the result object using Get methods or call back function As a result.Set of tasks storage module, for when the sets of threads and the sets of threads line that do not have the free time in the sets of threads thread pool Cheng Chi task queue less than when, the set of tasks is stored in the task queue, to wait the idle thread Group performs the set of tasks.Refuse tactful processing module, for when the task queue is expired, coming using refusal strategy Processing.
From the above, it can be seen that the sets of threads thread pool existing for create in a manner of sets of threads, by the free time Sets of threads specifically performs set of tasks so that sets of threads thread pool is after a set of tasks is received, moreover it is possible to performs other Business set, improve the utilization rate of sets of threads thread pool;Cancel having not carried out for task by using Future Cancel methods Or cancel being carrying out for task using interrupt mechanism;The implementing result of set of tasks is obtained by way of call back function, Provide a kind of mode of new acquisition implementing result.
Fig. 6 shows the example system of the task processing method or Task Processing Unit that can apply the embodiment of the present invention Framework 600.
As shown in fig. 6, system architecture 600 can include terminal device 601,602,603, network 604 and server 605. Network 604 between terminal device 601,602,603 and server 605 provide communication link medium.Network 604 can be with Including various connection types, such as wired, wireless communication link or fiber optic cables etc..
User can be interacted with using terminal equipment 601,602,603 by network 604 with server 605, to receive or send out Send message etc..Various telecommunication customer end applications, such as the application of shopping class, net can be installed on terminal device 601,602,603 (merely illustrative) such as the application of page browsing device, searching class application, JICQ, mailbox client, social platform softwares.
Terminal device 601,602,603 can have a display screen and a various electronic equipments that supported web page browses, bag Include but be not limited to smart mobile phone, tablet personal computer, pocket computer on knee and desktop computer etc..
Server 605 can be to provide the server of various services, such as utilize terminal device 601,602,603 to user The shopping class website browsed provides the back-stage management server (merely illustrative) supported.Back-stage management server can be to receiving To the data such as information query request analyze etc. processing, and by result (such as target push information, product letter Breath -- merely illustrative) feed back to terminal device.
It should be noted that the task processing method that the embodiment of the present application is provided typically is performed by server 605, accordingly Ground, Task Processing Unit are generally positioned in server 605.
It should be understood that the number of the terminal device, network and server in Fig. 6 is only schematical.According to realizing need Will, can have any number of terminal device, network and server.
According to an embodiment of the invention, present invention also offers a kind of electronic equipment and a kind of computer-readable medium.
The electronic equipment of the present invention includes:One or more processors;Storage device, for storing one or more journeys Sequence, when one or more of programs are by one or more of computing devices so that one or more of processors are real A kind of task processing method of the existing embodiment of the present invention.
The computer-readable medium of the present invention, is stored thereon with computer program, real when described program is executed by processor A kind of task processing method of the existing embodiment of the present invention.
Below with reference to Fig. 7, it illustrates suitable for realizing the computer system 700 of the electronic equipment of the embodiment of the present invention Structural representation.Electronic equipment shown in Fig. 7 is only an example, to the function of the embodiment of the present invention and should not use model Shroud carrys out any restrictions.
As shown in fig. 7, computer system 700 includes CPU (CPU) 701, it can be read-only according to being stored in Program in memory (ROM) 702 or be loaded into program in random access storage device (RAM) 703 from storage part 708 and Perform various appropriate actions and processing.In RAM 703, also it is stored with computer system 700 and operates required various programs And data.CPU 701, ROM 702 and RAM 703 are connected with each other by bus 704.Input/output (I/O) interface 705 It is connected to bus 704.
I/O interfaces 705 are connected to lower component:Importation 706 including keyboard, mouse etc.;Penetrated including such as negative electrode The output par, c 707 of spool (CRT), liquid crystal display (LCD) etc. and loudspeaker etc.;Storage part 708 including hard disk etc.; And the communications portion 709 of the NIC including LAN card, modem etc..Communications portion 709 via such as because The network of spy's net performs communication process.Driver 710 is also according to needing to be connected to I/O interfaces 705.Detachable media 711, such as Disk, CD, magneto-optic disk, semiconductor memory etc., it is arranged on as needed on driver 710, in order to read from it Computer program be mounted into as needed storage part 708.
Especially, may be implemented as counting according to embodiment disclosed by the invention, the process of key step figure description above Calculation machine software program.For example, embodiment of the disclosure includes a kind of computer program product, it includes being carried on computer-readable Computer program on medium, the computer program include the program code for being used for performing the method shown in key step figure. In such embodiment, the computer program can be downloaded and installed by communications portion 709 from network, and/or from can Medium 711 is dismantled to be mounted.When the computer program is performed by CPU (CPU) 701, system of the invention is performed The above-mentioned function of middle restriction.
It should be noted that the computer-readable medium shown in the present invention can be computer-readable signal media or meter Calculation machine readable storage medium storing program for executing either the two any combination.Computer-readable recording medium for example can be --- but not Be limited to --- electricity, magnetic, optical, electromagnetic, system, device or the device of infrared ray or semiconductor, or it is any more than combination.Meter The more specifically example of calculation machine readable storage medium storing program for executing can include but is not limited to:Electrical connection with one or more wires, just Take formula computer disk, hard disk, random access storage device (RAM), read-only storage (ROM), erasable type and may be programmed read-only storage Device (EPROM or flash memory), optical fiber, portable compact disc read-only storage (CD-ROM), light storage device, magnetic memory device, Or above-mentioned any appropriate combination.In the present invention, computer-readable recording medium can any include or store journey The tangible medium of sequence, the program can be commanded the either device use or in connection of execution system, device.And at this In invention, computer-readable signal media can include in a base band or as carrier wave a part propagation data-signal, Wherein carry computer-readable program code.The data-signal of this propagation can take various forms, including but unlimited In electromagnetic signal, optical signal or above-mentioned any appropriate combination.Computer-readable signal media can also be that computer can Any computer-readable medium beyond storage medium is read, the computer-readable medium, which can send, propagates or transmit, to be used for By instruction execution system, device either device use or program in connection.Included on computer-readable medium Program code can be transmitted with any appropriate medium, be included but is not limited to:Wirelessly, electric wire, optical cable, RF etc., or it is above-mentioned Any appropriate combination.
Flow chart and block diagram in accompanying drawing, it is illustrated that according to the system of various embodiments of the invention, method and computer journey Architectural framework in the cards, function and the operation of sequence product.At this point, each square frame in flow chart or block diagram can generation The part of one unit of table, program segment or code, a part for said units, program segment or code include one or more For realizing the executable instruction of defined logic function.It should also be noted that some as replace realization in, institute in square frame The function of mark can also be with different from the order marked in accompanying drawing generation.For example, two square frames succeedingly represented are actual On can perform substantially in parallel, they can also be performed in the opposite order sometimes, and this is depending on involved function.Also It is noted that the combination of each square frame and block diagram in block diagram or flow chart or the square frame in flow chart, can use and perform rule Fixed function or the special hardware based system of operation are realized, or can use the group of specialized hardware and computer instruction Close to realize.
Being described in module involved in the embodiment of the present invention can be realized by way of software, can also be by hard The mode of part is realized.Described module can also be set within a processor, for example, can be described as:A kind of processor bag Include creation module, call afferent module, set of tasks afferent module and receiving module.Wherein, the title of these modules is at certain In the case of do not form restriction to the module in itself, for example, creation module is also described as " creating sets of threads thread Pond, the sets of threads thread pool include multiple sets of threads, and the sets of threads includes the module of multiple threads ".
As on the other hand, present invention also offers a kind of computer-readable medium, the computer-readable medium can be Included in equipment described in above-described embodiment;Can also be individualism, and without be incorporated the equipment in.Above-mentioned calculating Machine computer-readable recording medium carries one or more program, when said one or multiple programs are performed by the equipment, makes Obtaining the equipment includes:Create sets of threads thread pool;Calling task dispatching method, current pending set of tasks is incoming described In method for scheduling task;When sets of threads available free in the sets of threads thread pool, by the method for scheduling task by institute State set of tasks and be passed to the sets of threads so that the sets of threads performs the set of tasks;Have not yet when in the set of tasks During the task of execution, using Future cancel described in the having not carried out of the task;When have in the set of tasks be carrying out appoint During business, cancel being carrying out for the task using interrupt mechanism;Receive next pending set of tasks.
From the above, it can be seen that the sets of threads thread pool existing for create in a manner of sets of threads, by the free time Sets of threads specifically performs set of tasks so that sets of threads thread pool is after a set of tasks is received, moreover it is possible to performs other Business set, improve the utilization rate of sets of threads thread pool;Cancel having not carried out for task by using Futrure Cancel methods Or cancel being carrying out for task using interrupt mechanism;The implementing result of set of tasks is obtained by way of call back function, Provide a kind of mode of new acquisition implementing result.
The said goods can perform the method that the embodiment of the present invention is provided, and possesses the corresponding functional module of execution method and has Beneficial effect.Not ins and outs of detailed description in the present embodiment, reference can be made to the method that the embodiment of the present invention is provided.
Above-mentioned embodiment, does not form limiting the scope of the invention.Those skilled in the art should be bright It is white, depending on design requirement and other factors, various modifications, combination, sub-portfolio and replacement can occur.It is any Modifications, equivalent substitutions and improvements made within the spirit and principles in the present invention etc., should be included in the scope of the present invention Within.

Claims (12)

  1. A kind of 1. task processing method, it is characterised in that including:
    Sets of threads thread pool is created, the sets of threads thread pool includes multiple sets of threads, and the sets of threads includes multiple threads;
    Calling task dispatching method, current pending set of tasks is passed in the method for scheduling task;
    When sets of threads available free in the sets of threads thread pool, the set of tasks is passed by the method for scheduling task Enter the sets of threads so that the sets of threads performs the set of tasks;
    When having having not carried out for task in the set of tasks, using Future cancel described in the having not carried out of the task;Work as institute State when having being carrying out for task in set of tasks, cancel being carrying out for the task using interrupt mechanism;
    Receive next pending set of tasks.
  2. 2. according to the method for claim 1, it is characterised in that the sets of threads performs the set of tasks, including:
    Each task in the set of tasks is stored in the task queue of the sets of threads;
    The method for scheduling task of the sets of threads is called, returns to the result object of each task.
  3. 3. method according to claim 1 or 2, it is characterised in that methods described also includes:Call back function is incoming described In method for scheduling task and the sets of threads.
  4. 4. according to the method for claim 3, it is characterised in that methods described also includes:Use Get methods or described time Letter of transfer number obtains the implementing result of the set of tasks from the result object.
  5. 5. according to the method for claim 1, it is characterised in that methods described also includes:
    When do not have in the sets of threads thread pool free time sets of threads and the sets of threads thread pool task queue less than when, will The set of tasks is stored in the task queue, to wait the idle sets of threads to perform the set of tasks;
    When the task queue of the sets of threads thread pool is expired, handled using refusal strategy.
  6. A kind of 6. Task Processing Unit, it is characterised in that including:
    Creation module, for creating sets of threads thread pool, the sets of threads thread pool includes multiple sets of threads, the sets of threads bag Include multiple threads;
    Afferent module is called, for calling task dispatching method, current pending set of tasks is passed to the task scheduling In method;
    Set of tasks afferent module, for when sets of threads available free in the sets of threads thread pool, being adjusted by the task The set of tasks is passed to the sets of threads so that the sets of threads performs the set of tasks by degree method;
    Cancel module, for when having having not carried out for task in the set of tasks, not yet being held using described in Future cancellations Capable task;When having being carrying out for task in the set of tasks, cancel using interrupt mechanism described be carrying out Task;
    Receiving module, for receiving next pending set of tasks.
  7. 7. device according to claim 6, it is characterised in that set of tasks afferent module, be additionally operable to:
    Each task in the set of tasks is stored in the task queue of the sets of threads;
    The method for scheduling task of the sets of threads is called, returns to the result object of each task.
  8. 8. the device according to claim 6 or 7, it is characterised in that described device also includes:Call back function afferent module, For call back function to be passed in the method for scheduling task and the sets of threads.
  9. 9. device according to claim 8, it is characterised in that described device also includes:Implementing result acquisition module, is used for The implementing result of the set of tasks is obtained from the result object using Get methods or call back function.
  10. 10. device according to claim 6, it is characterised in that described device also includes:
    Set of tasks storage module, for when the sets of threads and the sets of threads thread that do not have the free time in the sets of threads thread pool The task queue in pond less than when, the set of tasks is stored in the task queue, to wait the idle sets of threads To perform the set of tasks;
    Refuse tactful processing module, for when the task queue of the sets of threads thread pool is expired, locating using refusal strategy Reason.
  11. 11. a kind of electronic equipment, it is characterised in that including:
    One or more processors;
    Storage device, for storing one or more programs,
    When one or more of programs are by one or more of computing devices so that one or more of processors are real The now method as described in any in claim 1-5.
  12. 12. a kind of computer-readable medium, is stored thereon with computer program, it is characterised in that described program is held by processor The method as described in any in claim 1-5 is realized during row.
CN201710961495.8A 2017-10-16 2017-10-16 A kind of task processing method and device Pending CN107766137A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710961495.8A CN107766137A (en) 2017-10-16 2017-10-16 A kind of task processing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710961495.8A CN107766137A (en) 2017-10-16 2017-10-16 A kind of task processing method and device

Publications (1)

Publication Number Publication Date
CN107766137A true CN107766137A (en) 2018-03-06

Family

ID=61268542

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710961495.8A Pending CN107766137A (en) 2017-10-16 2017-10-16 A kind of task processing method and device

Country Status (1)

Country Link
CN (1) CN107766137A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110688203A (en) * 2018-07-05 2020-01-14 武汉斗鱼网络科技有限公司 Task execution method and device
WO2020259227A1 (en) * 2019-06-28 2020-12-30 Oppo广东移动通信有限公司 Thread task communication system, method, and related product
WO2022126532A1 (en) * 2020-12-17 2022-06-23 华为技术有限公司 Data processing method and apparatus

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101599027A (en) * 2009-06-30 2009-12-09 中兴通讯股份有限公司 A kind of thread pool management method and system thereof
CN102609316A (en) * 2012-02-07 2012-07-25 中山爱科数字科技股份有限公司 Management system and management method of network computing resource
CN104899099A (en) * 2015-05-26 2015-09-09 北京金和网络股份有限公司 Task allocation method based on thread pool
CN104915258A (en) * 2015-06-09 2015-09-16 北京京东尚科信息技术有限公司 Distributed task scheduling method and device
US20160239346A1 (en) * 2013-11-12 2016-08-18 Oxide Interactive, LLC Method and system of a hierarchical task scheduler for a multi-thread system
CN106528065A (en) * 2015-09-14 2017-03-22 阿里巴巴集团控股有限公司 Thread obtaining method and device
CN106861182A (en) * 2017-04-05 2017-06-20 天津卓越互娱科技有限公司 The method and server management system of a kind of efficient utilization server resource

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101599027A (en) * 2009-06-30 2009-12-09 中兴通讯股份有限公司 A kind of thread pool management method and system thereof
CN102609316A (en) * 2012-02-07 2012-07-25 中山爱科数字科技股份有限公司 Management system and management method of network computing resource
US20160239346A1 (en) * 2013-11-12 2016-08-18 Oxide Interactive, LLC Method and system of a hierarchical task scheduler for a multi-thread system
CN104899099A (en) * 2015-05-26 2015-09-09 北京金和网络股份有限公司 Task allocation method based on thread pool
CN104915258A (en) * 2015-06-09 2015-09-16 北京京东尚科信息技术有限公司 Distributed task scheduling method and device
CN106528065A (en) * 2015-09-14 2017-03-22 阿里巴巴集团控股有限公司 Thread obtaining method and device
CN106861182A (en) * 2017-04-05 2017-06-20 天津卓越互娱科技有限公司 The method and server management system of a kind of efficient utilization server resource

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
PRAVEER GUPTA: ""Understanding Thread Interruption in Java"", 《HTTPS://DZONE.COM/ARTICLES/UNDERSTANDING-THREAD-INTERRUPTION-IN-JAVA》 *
王新春: ""基于并发执行时间配额控制的任务调度框架"", 《信息技术与标准化》 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110688203A (en) * 2018-07-05 2020-01-14 武汉斗鱼网络科技有限公司 Task execution method and device
CN110688203B (en) * 2018-07-05 2022-05-13 武汉斗鱼网络科技有限公司 Task execution method and device
WO2020259227A1 (en) * 2019-06-28 2020-12-30 Oppo广东移动通信有限公司 Thread task communication system, method, and related product
WO2022126532A1 (en) * 2020-12-17 2022-06-23 华为技术有限公司 Data processing method and apparatus

Similar Documents

Publication Publication Date Title
CN107729139A (en) A kind of method and apparatus for concurrently obtaining resource
CN107885590A (en) Task processing method and device for smart machine
CN104657220B (en) Scheduling model and method based on deadline and expense restriction in mixed cloud
CN107590186A (en) Management and the method and policy engine system for performing data processing policy
CN110310034A (en) A kind of service orchestration applied to SaaS, business flow processing method and apparatus
CN110197350A (en) A kind of article warehouse-out method and device
CN108346028A (en) A kind of business approval processing method, apparatus and system
CN110825535B (en) Job scheduling method and system
CN109308214A (en) Data task processing method and system
CN108920222A (en) A kind of method and device for business processing of rule-based engine
CN102012840A (en) Batch data scheduling method and system
CN110245011A (en) A kind of method for scheduling task and device
CN107766137A (en) A kind of task processing method and device
CN107844371A (en) Task processing method, system and electronic equipment
CN109582452A (en) A kind of container dispatching method, dispatching device and electronic equipment
CN107463434A (en) Distributed task processing method and device
CN107329978A (en) The method for routing and device of multi-platform fusion
CN108932157A (en) Method, system, electronic equipment and the readable medium of distributed treatment task
CN109408286A (en) Data processing method, device, system, computer readable storage medium
CN110457142A (en) Method for processing business, system, computer room, framework and electronic equipment
CN107463642A (en) The method and apparatus for lifting Tool for Data Warehouse resource utilization
CN107070709A (en) A kind of NFV implementation methods based on bottom NUMA aware
CN108628669A (en) A kind of method and apparatus of scheduling machine learning algorithm task
CN109597699A (en) Data processing method, device, electronic equipment and computer-readable medium
CN109725988A (en) A kind of method for scheduling task and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20180306