CN106020954A - Thread management method and device - Google Patents
Thread management method and device Download PDFInfo
- Publication number
- CN106020954A CN106020954A CN201610318792.6A CN201610318792A CN106020954A CN 106020954 A CN106020954 A CN 106020954A CN 201610318792 A CN201610318792 A CN 201610318792A CN 106020954 A CN106020954 A CN 106020954A
- Authority
- CN
- China
- Prior art keywords
- thread
- task
- weights
- pool
- newly
- 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
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
- G06F9/4843—Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
- G06F9/4881—Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5027—Allocation 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/5038—Allocation 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
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/48—Indexing scheme relating to G06F9/48
- G06F2209/484—Precedence
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/50—Indexing scheme relating to G06F9/50
- G06F2209/5018—Thread allocation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/50—Indexing scheme relating to G06F9/50
- G06F2209/5021—Priority
Abstract
The invention discloses a thread management method. The method comprises the following procedures: if a task processing request is received, determining a task included in the task processing request and the task type as well as the task ID of the task; judging whether a free thread matching the task type exists in a thread pool; if the free thread matching the task type does not exist in the thread pool, determining the priority weight of the task based on the task ID; when the priority weight is greater than a preset weight, building a new thread matching the task type in the thread pool and distributing the task to the newly built thread for processing. The invention also discloses a thread management device. According to the thread management method and device, the technical problem that the task with a high requirement on real-time performance is delayed for processing in the prior art is solved.
Description
Technical field
The present invention relates to field of computer technology, particularly relate to a kind of thread management method and device.
Background technology
Along with developing rapidly of computer technology, cloud computing progressively becomes the focus point of industry, each big business
Have been added in the research field of cloud computing, and cloud computing service is put into science, culture, education,
Multiple fields such as health, government, ecommerce, high-performance calculation, Internet of Things use.
At present, cloud data center management platform ensures when receiving task by setting up thread pool, should
Task distributes in this thread pool and performs.Thread, sometimes referred to as Lightweight Process, is that program performs stream
Minimum unit, the thread of a standard is by Thread Id, current instruction pointer, set of registers and storehouse group
Become.It addition, thread is an entity in process, the ultimate unit independently dispatched by system and assign,
Thread oneself does not have system resource, only has any requisite resource that is in operation, but it can be with
Other thread belonging to a process together shares whole resources that process is had.One thread can set up and
Cancel another thread, can concurrently perform between the multiple threads in same process.Between thread
Mutual restriction, cause thread to be in operation and present discontinuity.Thread is the most available free, block and busy
Three kinds of basic status.
In single program, run multiple thread the most simultaneously complete different tasks, referred to as multithreading,
In systems development process, often use the task events that multiple threads is different, have some tasks holding
During row, the requirement for real-time is the highest, but the longest, when the thread in thread pool is equal when being carried out
When being in busy state, only after these tasks carryings terminate, i.e. can continue when the thread pool free time
Other tasks that continuous execution is follow-up, and follow-up required these other tasks performed may have one to real-time
Provisioning request, thus cause the task to requirement of real-time is high to be delayed.
Summary of the invention
The present invention provides a kind of thread management method and device, and its main purpose is to solve in prior art
The task that requirement of real-time is high is delayed the technical problem of process.
For achieving the above object, the present invention provides a kind of thread management method, and this thread management method includes:
If the task that receives processes request, it is determined that described task processes the task and institute comprised in request
State task type and the task identification of task;
Judge whether thread pool has the idle thread mated with described task type;
If the idle thread do not mated with described task type in described Cheng Chi, then according to described task mark
Know the weights determining described task;
When described weights is more than preset weights, newly-built and described task class in described thread pool
The thread of type coupling, and the distribution of described task is processed to newly-built described thread.
Alternatively, the described thread that newly-built and described task type mates in described thread pool, and by institute
Stating before task distribution carries out, to the most newly-built described thread, the step processed, described thread management method is also wrapped
Include:
When described weights is more than preset weights, it is judged that whether the number of threads in described thread pool
Reach the first preset number;
If the preset number in described thread pool is not up to described first preset number, then perform at described line
The thread that in Cheng Chi, newly-built and described task type mates, and by the distribution of described task to the most newly-built described line
The step that Cheng Jinhang processes;
If the preset number in described thread pool reaches described first preset number, then judge described thread pool
Buffer queue whether include buffer;
If the buffer queue of described thread pool includes buffer, described task is put into described buffer queue
In, and the task in described buffer queue is arranged according to weights order from high to low.
Alternatively, if described Cheng Chi the idle thread do not mated with described task type, then root
Determine the step of weights of described task according to described task identification after, described thread management method
Also include:
When described weights is less than or equal to described preset weights, it is judged that delaying of described thread pool
Rush whether queue includes buffer;
If the buffer queue of described thread pool includes buffer, described task is put into described buffer queue
In, and the task in described buffer queue is arranged according to weights order from high to low.
Alternatively, described when described weights is more than preset weights, newly-built in described thread pool
The thread mated with described task type, and the distribution of described task is processed to newly-built described thread
Step after, described thread management method further comprises the steps of:
In the thread state managing listings that described thread pool is corresponding, by the state mark of newly-built described thread
It is designated as busy state.
Alternatively, described thread management method further comprises the steps of:
According to the thread state managing listings that described thread pool is corresponding, monitor in real time in described thread pool each
The state of thread;
When available free thread being detected, it is judged that whether number of threads current in described thread pool is more than the
Two preset number, wherein, described second preset number is less than described first preset number;
If number of threads current in described thread is more than the second preset number, the then described sky that will detect
Idle thread is destroyed.
Additionally, for achieving the above object, the present invention also provides for a kind of thread management device, this thread management
Device includes:
First determines module, if processing request for receiving task, it is determined that described task processes request
In the task of comprising and the task type of described task and task identification;
First judge module, for judging whether there is the idle line mated with described task type in thread pool
Journey;
Second determines module, if the idle thread do not mated with described task type in described Cheng Chi,
The weights of described task is then determined according to described task identification;
Task processing module, for when described weights is more than preset weights, at described thread pool
In the thread that mates of newly-built and described task type, and the distribution of described task is entered to the most newly-built described thread
Row processes.
Alternatively, described thread management device also includes:
Second judge module, for when described weights is more than preset weights, it is judged that described thread
Whether the number of threads in pond reaches the first preset number;
Described task processing module, if the preset number being additionally operable in described thread pool is not up to described first
Preset number, then the thread that newly-built in described thread pool and described task type mates, and by described
Business distribution processes to newly-built described thread;
Described second judge module, if the preset number being additionally operable in described thread pool reaches described first pre-
If number, then judge whether the buffer queue of described thread pool includes buffer;
Described task processing module, if the buffer queue being additionally operable to described thread pool includes buffer, will
Described task is put in described buffer queue, and by the task in described buffer queue according to weights
Order from high to low arranges.
Alternatively, described first judge module, it is additionally operable to when described weights is less than or equal to institute
When stating preset weights, it is judged that whether the buffer queue of described thread pool includes buffer;
Described task processing module, if the buffer queue being additionally operable to described thread pool includes buffer, will
Described task is put in described buffer queue, and by the task in described buffer queue according to weights
Order from high to low arranges.
Alternatively, described thread management device also includes:
Status indication module, in the thread state managing listings that described thread pool is corresponding, by newly-built
The status indication of described thread be busy state.
Alternatively, described thread management device also includes:
State monitoring module, for the thread state managing listings corresponding according to described thread pool, supervises in real time
Survey the state of each thread in described thread pool;
3rd judge module, for when detecting available free thread, it is judged that current in described thread pool
Whether number of threads is more than the second preset number, and wherein, described second preset number is first pre-less than described
If number;
Thread destruction module, if number of threads current in described thread is more than the second preset number,
Then the described idle thread detected is destroyed.
The thread management method of present invention proposition and device, when receiving task and processing request, determine and appoint
Business processes the task and the task type of task and task identification comprised in request, and judges in thread pool
Whether there is the idle thread mated with task type, if it is not, determine task according to task identification
Weights, when weights is more than preset weights, illustrates that requirement of real-time is compared by this task
Height, needs to process in time, now, and the newly-built thread mated with this task type in thread pool, and will
Task distribution processes to newly-built thread, and the present invention avoids when not having idle thread, directly will appoint
Business is put in buffer queue, it is possible to ensure that the high task of weights, by priority treatment, solves existing
The task that in technology, requirement of real-time is high is delayed the technical problem of process.
Accompanying drawing explanation
Fig. 1 is the flow chart of thread management method first embodiment of the present invention;
Fig. 2 is the flow chart of thread management method the 4th embodiment of the present invention;
Fig. 3 is the high-level schematic functional block diagram of thread management device first embodiment of the present invention;
Fig. 4 is the high-level schematic functional block diagram of thread management device the 4th embodiment of the present invention.
The realization of the object of the invention, functional characteristics and advantage will in conjunction with the embodiments, do referring to the drawings further
Explanation.
Detailed description of the invention
Should be appreciated that specific embodiment described herein, only in order to explain the present invention, is not used to limit
Determine the present invention.
The present invention provides a kind of thread management method.With reference to shown in Fig. 1, for thread management method of the present invention
The flow chart of first embodiment.
In the present embodiment, this thread management method includes:
Step S10, if the task that receives processes request, it is determined that comprise in the process request of described task appoints
Business and the task type of described task and task identification.
Step S20, it is judged that whether have the idle thread mated with described task type in thread pool.
In the present embodiment, for the distribution side of task, when distributing task, need at task
Adding task type and the task identification of this task in reason request, wherein, task type is used for judging to need
Task distribution to which thread will be processed, the task identification foundation of the weights of acquisition task.
After the task that receives processes request, determine that task processes the task and described comprised in request
Service type and task identification, then judge in thread pool, if has the idle thread mated with task type,
This thread i.e. is currently at idle condition, and can process the task of the above-mentioned type.
It should be noted that the thread in existing thread pool can be supervised by thread management system in real time
Survey, and set up thread state managing listings, comprise in this thread state managing listings thread mark,
Task type that this thread can process and current state.And thread management system can be based on monitoring
State change amendment this thread state in thread condition managing list of thread so that this thread state
Managing listings can reflect the state of each thread in thread pool in real time.
The state of thread includes idle condition, busy state and blocked state.One thread is once only capable of place
Managing a task, therefore, after the thread distribution task to an idle condition, this thread will immediately
Process this task, and the state of this thread will be also busy state by idle state transition.Wherein, thread
It is in blocked state and refers to that thread can process task, but there is its process task of certain condition tissue,
And when thread is in blocked state, thread management system will ignore this thread, not distribute task for it,
And also will not distribute any CPU time for this thread, until this thread enters idle condition, can be just it
Distribution task.
The multiple different thread created in thread pool, for processing the task of different types, is used for processing
Each type of number of threads can have one or more, and its number can be arranged as required to.
Step S30, if the idle thread do not mated with described task type in described Cheng Chi, then according to institute
State task identification and determine the weights of described task.
Step S40, when described weights is more than preset weights, newly-built and institute in described thread pool
State the thread of task type coupling, and the distribution of described task is processed to newly-built described thread.
When thread pool does not has idle thread in the thread processing task corresponding to described task type,
Then explanation can process the thread of task corresponding to described task type and be in busy state, or have
It is in blocked state and cannot use, now, determine the weights of task according to described task identification,
Wherein, different task identifications represents different weights, and weights is the highest, then this task
Requirement to real-time is the highest, if weights is more than preset weights, then illustrates that this task is to real-time
Requirement higher, need this task of priority treatment, then in thread pool, create new and task type
The thread of coupling, by task distribution to newly-built thread process, wherein, preset weights can be by user's root
Arrange according to needs.
Further, after the step s 40, the method further comprises the steps of:
In the thread state managing listings that described thread pool is corresponding, by the state mark of newly-built described thread
It is designated as busy state.
The thread management method that the present embodiment proposes, when receiving task and processing request, determines at task
The task of comprising and the task type of task and task identification in reason request, and whether judge in thread pool
There is the idle thread mated with task type, if it is not, determine the preferential of task according to task identification
Level weights, when weights is more than preset weights, illustrate that this task is higher to requirement of real-time,
Need to process in time, now, the newly-built thread mated with this task type in thread pool, and by task
Distribution processes to newly-built thread, and the present invention avoids, when not having idle thread, directly task being put
In buffer queue, it is possible to ensure that the high task of weights, by priority treatment, solves prior art
The task that middle requirement of real-time is high is delayed the technical problem of process.
Second embodiment of thread management method of the present invention is proposed based on first embodiment.In the present embodiment,
Before step S40, the method further comprises the steps of:
When described weights is more than preset weights, it is judged that whether the number of threads in described thread pool
Reach the first preset number;
If the preset number in described thread pool is not up to described first preset number, then perform at described line
The thread that in Cheng Chi, newly-built and described task type mates, and by the distribution of described task to the most newly-built described line
The step that Cheng Jinhang processes;
If the preset number in described thread pool reaches described first preset number, then judge described thread pool
Buffer queue whether include buffer;
If the buffer queue of described thread pool includes buffer, described task is put into described buffer queue
In, and the task in described buffer queue is arranged according to weights order from high to low.
In the present embodiment, when weights is more than preset weights, thread pool thread is first judged
Quantity has reached the first preset number, and wherein, the first preset number is that system resource can load
The upper limit of number of threads, if number of threads is too much, cause system load excessive, may affect and work as
The process of front task, therefore, in order to avoid number of threads is beyond load, when the quantity of thread pool thread
During not up to the first preset number, the thread that newly-built and described task type mates in described thread pool,
And the distribution of described task is processed to newly-built described thread;If having reached the first preset number,
Then judging whether buffer queue also has buffer, if having, then task being put in buffer queue, and
Task in buffer queue is arranged according to weights order from high to low.If no, then
Refuse this task.
3rd embodiment of thread management method of the present invention is proposed based on the second embodiment.In the present embodiment,
After step S30, this thread management method is further comprising the steps of:
When described weights is less than or equal to described preset weights, it is judged that delaying of described thread pool
Rush whether queue includes buffer;
If the buffer queue of described thread pool includes buffer, described task is put into described buffer queue
In, and the task in described buffer queue is arranged according to weights order from high to low.
In the present embodiment, in order to guarantee there is enough system resource to process current task,
The weights of described task is relatively low to the requirement of real-time less than preset weights, i.e. this task, and slow
When rushing queue Zhong You buffer, during just task puts into buffer queue, and by the task in buffer queue
Arrange according to weights order from high to low.
Based on first embodiment, the second embodiment or the 3rd embodiment, thread management method of the present invention is proposed
The 4th embodiment.With reference to shown in Fig. 2, in the present embodiment, this thread management method also includes following
Step:
Step S50, according to the thread state managing listings that described thread pool is corresponding, monitors described thread in real time
The state of each thread in pond;
Step S60, when detecting available free thread, it is judged that number of threads current in described thread pool is
No second preset number that is more than, wherein, described second preset number is less than described first preset number;
Step S70, if number of threads current in described thread is more than the second preset number, then will detect
Described idle thread destroy.
In order to save system resource, according to the thread state managing listings that thread pool is corresponding, in thread pool
The state of each thread monitor in real time, when detecting in available free thread and current thread pond
When number of threads is more than the second preset number, the described idle thread detected is destroyed.Otherwise, retain
The thread pool of these free time, for receiving new task.
Wherein, described second preset number is less than the first preset number, can be arranged as required to by user,
When the number of threads in thread pool is less than the second preset number, system resource reasonable distribution can be enable,
Current task is made to have processing speed faster.
The present invention also proposes a kind of thread management device.
With reference to shown in Fig. 3, for the high-level schematic functional block diagram of thread management device first embodiment of the present invention.
In this embodiment, this thread management device includes:
First determines module 10, if processing request for receiving task, it is determined that described task processes please
Comprising in asking of task and the task type of described task and task identification.
First judge module 20, for judging whether there is the free time mated with described task type in thread pool
Thread.
In the present embodiment, for the distribution side of task, when distributing task, need at task
Adding task type and the task identification of this task in reason request, wherein, task type is used for judging to need
Task distribution to which thread will be processed, the task identification foundation of the weights of acquisition task.
After the task that receives processes request, first determines that module 10 determines what task process comprised in asking
Task and described task type and task identification, then the first judge module 20 judges in thread pool, is
No have the idle thread mated with task type, i.e. this thread to be currently at idle condition, and can process
The task of the above-mentioned type.
It should be noted that the thread in existing thread pool can be supervised by thread management system in real time
Survey, and set up thread state managing listings, comprise in this thread state managing listings thread mark,
Task type that this thread can process and current state.And thread management system can be based on monitoring
State change amendment this thread state in thread condition managing list of thread so that this thread state
Managing listings can reflect the state of each thread in thread pool in real time.
The state of thread includes idle condition, busy state and blocked state.One thread is once only capable of place
Managing a task, therefore, after the thread distribution task to an idle condition, this thread will immediately
Process this task, and the state of this thread will be also busy state by idle state transition.Wherein, thread
It is in blocked state and refers to that thread can process task, but there is its process task of certain condition tissue,
And when thread is in blocked state, thread management system will ignore this thread, not distribute task for it,
And also will not distribute any CPU time for this thread, until this thread enters idle condition, can be just it
Distribution task.
The multiple different thread created in thread pool, for processing the task of different types, is used for processing
Each type of number of threads can have one or more, and its number can be arranged as required to.
Second determines module 30, if the idle line not mated with described task type in described Cheng Chi
Journey, then determine the weights of described task according to described task identification.
Task processing module 40, for when described weights is more than preset weights, at described thread
The thread that in pond, newly-built and described task type mates, and by the distribution of described task to the most newly-built described thread
Process.
When thread pool does not has idle thread in the thread processing task corresponding to described task type,
Then explanation can process the thread of task corresponding to described task type and be in busy state, or have
Being in blocked state and cannot use, now, second determines that module 30 determines according to described task identification appoints
The weights of business, wherein, different task identifications represents different weights, and priority is weighed
Be worth the highest, then this task is the highest to the requirement of real-time, if weights is more than preset weights, then says
This task bright is higher to the requirement of real-time, needs this task of priority treatment, then task processing module
40 create the new thread mated with task type in thread pool, at task distribution to newly-built thread
Reason, wherein, preset weights can be arranged as required to by user.
Further, this device also includes:
Status indication module, in the thread state managing listings that described thread pool is corresponding, by newly-built
The status indication of described thread be busy state.
The thread management device that the present embodiment proposes, when receiving task and processing request, determines at task
The task of comprising and the task type of task and task identification in reason request, and whether judge in thread pool
There is the idle thread mated with task type, if it is not, determine the preferential of task according to task identification
Level weights, when weights is more than preset weights, illustrate that this task is higher to requirement of real-time,
Need to process in time, now, the newly-built thread mated with this task type in thread pool, and by task
Distribution processes to newly-built thread, and the present invention avoids, when not having idle thread, directly task being put
In buffer queue, it is possible to ensure that the high task of weights, by priority treatment, solves prior art
The task that middle requirement of real-time is high is delayed the technical problem of process.
Second embodiment of thread management device of the present invention is proposed based on first embodiment.In the present embodiment,
This device also includes:
Second judge module, for when described weights is more than preset weights, it is judged that described thread
Whether the number of threads in pond reaches the first preset number;
Task processing module 40, if the preset number being additionally operable in described thread pool is not up to described first pre-
If number, then perform the thread that newly-built in described thread pool and described task type mates, and by described
Task distribution carries out the step processed to newly-built described thread;
Second judge module, if the preset number being additionally operable in described thread pool reaches described first present count
Mesh, then judge whether the buffer queue of described thread pool includes buffer;
Task processing module 40, if the buffer queue being additionally operable to described thread pool includes buffer, by institute
The task of stating is put in described buffer queue, and by the task in described buffer queue according to weights by
High to Low order arranges.
In the present embodiment, when weights is more than preset weights, the second judge module first judges line
The quantity of Cheng Chi thread has reached the first preset number, and wherein, the first preset number is system
The upper limit of the number of threads that resource can load, if number of threads is too much, causes system load excessive,
The process of current task may be affected, therefore, in order to avoid number of threads is beyond load, work as thread pool
When the quantity of thread is not up to the first preset number, task processing module 40 is newly-built in described thread pool
The thread mated with described task type, and the distribution of described task is processed to newly-built described thread;
If having reached the first preset number, then judge whether buffer queue also has buffer, if having, then
Task is put in buffer queue by task processing module 40, and by the task in buffer queue according to priority
Weights order from high to low arranges.If no, then refusing this task.
3rd embodiment of thread management device of the present invention is proposed based on first embodiment.In the present embodiment,
First judge module 20, is additionally operable to when described weights is less than or equal to described preset weights,
Judge whether the buffer queue of described thread pool includes buffer;
Task processing module 40, if the buffer queue being additionally operable to described thread pool includes buffer, by institute
The task of stating is put in described buffer queue, and by the task in described buffer queue according to weights by
High to Low order arranges.
In the present embodiment, in order to guarantee there is enough system resource to process current task,
The weights of described task is relatively low to the requirement of real-time less than preset weights, i.e. this task, and slow
When rushing queue Zhong You buffer, task processing module 40 is during just task puts into buffer queue, and will be slow
The task in queue of rushing arranges according to weights order from high to low.
Based on first embodiment, the second embodiment or the 3rd embodiment, thread management device of the present invention is proposed
The 4th embodiment.With reference to shown in Fig. 4, in the present embodiment, this thread management device also includes:
State monitoring module 50, for the thread state managing listings corresponding according to described thread pool, in real time
Monitor the state of each thread in described thread pool;
3rd judge module 60, for when detecting available free thread, it is judged that current in described thread pool
Number of threads whether more than the second preset number, wherein, described second preset number is less than described first
Preset number;
Thread destruction module 70, if number of threads current in described thread is more than the second preset number,
Then the described idle thread detected is destroyed.
In order to save system resource, state monitoring module 50 arranges according to the thread state management that thread pool is corresponding
Table, monitors in real time to the state of each thread in thread pool, when detect available free thread and
When number of threads in current thread pond is more than the second preset number, thread destruction module 70 will detect
Described idle thread is destroyed.Otherwise, retain the thread pool of these free time, for receiving new task.
Wherein, described second preset number is less than the first preset number, can be arranged as required to by user,
When the number of threads in thread pool is less than the second preset number, system resource reasonable distribution can be enable,
Current task is made to have processing speed faster.
These are only the preferred embodiments of the present invention, not thereby limit the scope of the claims of the present invention, every
Utilize equivalent structure or equivalence flow process conversion that description of the invention and accompanying drawing content made, or directly or
Connect and be used in other relevant technical fields, be the most in like manner included in the scope of patent protection of the present invention.
Claims (10)
1. a thread management method, it is characterised in that described thread management method includes:
If the task that receives processes request, it is determined that described task processes the task and institute comprised in request
State task type and the task identification of task;
Judge whether thread pool has the idle thread mated with described task type;
If the idle thread do not mated with described task type in described Cheng Chi, then according to described task mark
Know the weights determining described task;
When described weights is more than preset weights, newly-built and described task class in described thread pool
The thread of type coupling, and the distribution of described task is processed to newly-built described thread.
Thread management method the most according to claim 1, it is characterised in that described at described thread
The thread that in pond, newly-built and described task type mates, and by the distribution of described task to the most newly-built described thread
Before carrying out the step processed, described thread management method also includes:
When described weights is more than preset weights, it is judged that whether the number of threads in described thread pool
Reach the first preset number;
If the preset number in described thread pool is not up to described first preset number, then perform at described line
The thread that in Cheng Chi, newly-built and described task type mates, and by the distribution of described task to the most newly-built described line
The step that Cheng Jinhang processes;
If the preset number in described thread pool reaches described first preset number, then judge described thread pool
Buffer queue whether include buffer;
If the buffer queue of described thread pool includes buffer, described task is put into described buffer queue
In, and the task in described buffer queue is arranged according to weights order from high to low.
Thread management method the most according to claim 1, it is characterised in that if described Cheng Chi
In the idle thread do not mated with described task type, then determine described task according to described task identification
Weights step after, described thread management method also includes:
When described weights is less than or equal to described preset weights, it is judged that delaying of described thread pool
Rush whether queue includes buffer;
If the buffer queue of described thread pool includes buffer, described task is put into described buffer queue
In, and the task in described buffer queue is arranged according to weights order from high to low.
Thread management method the most according to claim 1, it is characterised in that described when described preferentially
When level weights are more than preset weights, the thread that newly-built and described task type mates in described thread pool,
And after the distribution of described task is carried out, to newly-built described thread, the step processed, described thread management side
Method further comprises the steps of:
In the thread state managing listings that described thread pool is corresponding, by the state mark of newly-built described thread
It is designated as busy state.
Thread management method the most according to any one of claim 1 to 4, it is characterised in that institute
State thread management method to further comprise the steps of:
According to the thread state managing listings that described thread pool is corresponding, monitor in real time in described thread pool each
The state of thread;
When available free thread being detected, it is judged that whether number of threads current in described thread pool is more than the
Two preset number, wherein, described second preset number is less than described first preset number;
If number of threads current in described thread is more than the second preset number, the then described sky that will detect
Idle thread is destroyed.
6. a thread management device, it is characterised in that described thread management device includes:
First determines module, if processing request for receiving task, it is determined that described task processes request
In the task of comprising and the task type of described task and task identification;
First judge module, for judging whether there is the idle line mated with described task type in thread pool
Journey;
Second determines module, if the idle thread do not mated with described task type in described Cheng Chi,
The weights of described task is then determined according to described task identification;
Task processing module, for when described weights is more than preset weights, at described thread pool
In the thread that mates of newly-built and described task type, and the distribution of described task is entered to the most newly-built described thread
Row processes.
Thread management device the most according to claim 6, it is characterised in that described thread management fills
Put and also include:
Second judge module, for when described weights is more than preset weights, it is judged that described thread
Whether the number of threads in pond reaches the first preset number;
Described task processing module, if the preset number being additionally operable in described thread pool is not up to described first
Preset number, then the thread that newly-built in described thread pool and described task type mates, and by described
Business distribution processes to newly-built described thread;
Described second judge module, if the preset number being additionally operable in described thread pool reaches described first pre-
If number, then judge whether the buffer queue of described thread pool includes buffer;
Described task processing module, if the buffer queue being additionally operable to described thread pool includes buffer, will
Described task is put in described buffer queue, and by the task in described buffer queue according to weights
Order from high to low arranges.
Thread management device the most according to claim 6, it is characterised in that described first judges mould
Block, is additionally operable to when described weights is less than or equal to described preset weights, it is judged that described thread
Whether the buffer queue in pond includes buffer;
Described task processing module, if the buffer queue being additionally operable to described thread pool includes buffer, will
Described task is put in described buffer queue, and by the task in described buffer queue according to weights
Order from high to low arranges.
Thread management device the most according to claim 6, it is characterised in that described thread management fills
Put and also include:
Status indication module, in the thread state managing listings that described thread pool is corresponding, by newly-built
The status indication of described thread be busy state.
10. according to the thread management device according to any one of claim 6 to 9, it is characterised in that
Described thread management device also includes:
State monitoring module, for the thread state managing listings corresponding according to described thread pool, supervises in real time
Survey the state of each thread in described thread pool;
3rd judge module, for when detecting available free thread, it is judged that current in described thread pool
Whether number of threads is more than the second preset number, and wherein, described second preset number is first pre-less than described
If number;
Thread destruction module, if number of threads current in described thread is more than the second preset number,
Then the described idle thread detected is destroyed.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610318792.6A CN106020954A (en) | 2016-05-13 | 2016-05-13 | Thread management method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610318792.6A CN106020954A (en) | 2016-05-13 | 2016-05-13 | Thread management method and device |
Publications (1)
Publication Number | Publication Date |
---|---|
CN106020954A true CN106020954A (en) | 2016-10-12 |
Family
ID=57100011
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610318792.6A Pending CN106020954A (en) | 2016-05-13 | 2016-05-13 | Thread management method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106020954A (en) |
Cited By (27)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106506389A (en) * | 2016-10-19 | 2017-03-15 | 广州华多网络科技有限公司 | Network request asynchronous processing method and device |
CN106547612A (en) * | 2016-10-18 | 2017-03-29 | 深圳怡化电脑股份有限公司 | A kind of multi-task processing method and device |
CN106648874A (en) * | 2016-12-30 | 2017-05-10 | 中国建设银行股份有限公司 | Processing method and device for batched task |
CN106648892A (en) * | 2016-12-12 | 2017-05-10 | 深圳市元征软件开发有限公司 | Allocation processing method and device for detection threads |
CN106953857A (en) * | 2017-03-16 | 2017-07-14 | 郑州云海信息技术有限公司 | A kind of server end Multithread management method based on CS frameworks |
CN107391243A (en) * | 2017-06-30 | 2017-11-24 | 广东神马搜索科技有限公司 | Thread task processing equipment, device and method |
CN108228240A (en) * | 2016-12-14 | 2018-06-29 | 北京国双科技有限公司 | The treating method and apparatus of task in multitask queue |
CN108681481A (en) * | 2018-03-13 | 2018-10-19 | 阿里巴巴集团控股有限公司 | The processing method and processing device of service request |
CN108984285A (en) * | 2018-06-28 | 2018-12-11 | 上海数据交易中心有限公司 | A kind of analysis of data collision flow point method and device, storage medium, terminal |
CN109388485A (en) * | 2018-09-26 | 2019-02-26 | 广州虎牙信息科技有限公司 | A kind of processing method, device, equipment and the storage medium of task execution thread |
CN109669776A (en) * | 2018-12-12 | 2019-04-23 | 北京文章无忧信息科技有限公司 | Processing method, the device and system of Detection task |
CN109756565A (en) * | 2018-12-26 | 2019-05-14 | 成都科来软件有限公司 | A kind of Multitask Data method for pushing based on statistical form |
CN109815007A (en) * | 2018-12-15 | 2019-05-28 | 平安科技(深圳)有限公司 | Thread control method, device, electronic equipment and storage medium based on cloud monitoring |
CN110321213A (en) * | 2019-07-08 | 2019-10-11 | 杭州港盛软件科技有限公司 | A kind of request processing method, device, equipment and readable storage medium storing program for executing |
CN110457124A (en) * | 2019-08-06 | 2019-11-15 | 中国工商银行股份有限公司 | For the processing method and its device of business thread, electronic equipment and medium |
CN110457126A (en) * | 2019-08-13 | 2019-11-15 | 杭州有赞科技有限公司 | A kind of asynchronous invoking method and system |
CN110515715A (en) * | 2019-08-22 | 2019-11-29 | 北京宝兰德软件股份有限公司 | Task processing method and device based on thread pool |
CN110750339A (en) * | 2018-07-23 | 2020-02-04 | 杭州海康威视系统技术有限公司 | Thread scheduling method and device and electronic equipment |
CN111124655A (en) * | 2018-10-31 | 2020-05-08 | 武汉斗鱼网络科技有限公司 | Network request scheduling method, terminal device and storage medium |
CN111491015A (en) * | 2020-03-31 | 2020-08-04 | 北京金山云网络技术有限公司 | Preheating task processing method and system, proxy server and service center |
CN111767125A (en) * | 2020-06-15 | 2020-10-13 | 杭州数梦工场科技有限公司 | Task execution method and device, electronic equipment and storage medium |
CN111782293A (en) * | 2020-06-28 | 2020-10-16 | 珠海豹趣科技有限公司 | Task processing method and device, electronic equipment and readable storage medium |
CN111782295A (en) * | 2020-06-29 | 2020-10-16 | 珠海豹趣科技有限公司 | Application program running method and device, electronic equipment and storage medium |
CN111857865A (en) * | 2020-06-28 | 2020-10-30 | 珠海豹趣科技有限公司 | Event type task processing method and device, electronic equipment and storage medium |
CN112395054A (en) * | 2019-08-15 | 2021-02-23 | 杭州海康威视系统技术有限公司 | Thread scheduling method, device and system |
CN112905326A (en) * | 2021-02-18 | 2021-06-04 | 上海哔哩哔哩科技有限公司 | Task processing method and device |
CN115037702A (en) * | 2022-05-23 | 2022-09-09 | 北京梧桐车联科技有限责任公司 | Message distribution method, data transmission method and equipment |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101290619A (en) * | 2007-04-20 | 2008-10-22 | 西北民族大学 | Content based Tibetan website tangka image search engine intelligent robot search method |
CN101777008A (en) * | 2009-12-31 | 2010-07-14 | 中兴通讯股份有限公司 | Method and device for realizing mobile terminal system thread pool |
CN102591721A (en) * | 2011-12-30 | 2012-07-18 | 北京新媒传信科技有限公司 | Method and system for distributing thread execution task |
CN103197968A (en) * | 2013-03-18 | 2013-07-10 | 焦点科技股份有限公司 | Thread pool processing method and system capable of fusing synchronous and asynchronous features |
CN105159768A (en) * | 2015-09-09 | 2015-12-16 | 浪潮集团有限公司 | Task management method and cloud data center management platform |
-
2016
- 2016-05-13 CN CN201610318792.6A patent/CN106020954A/en active Pending
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101290619A (en) * | 2007-04-20 | 2008-10-22 | 西北民族大学 | Content based Tibetan website tangka image search engine intelligent robot search method |
CN101777008A (en) * | 2009-12-31 | 2010-07-14 | 中兴通讯股份有限公司 | Method and device for realizing mobile terminal system thread pool |
CN102591721A (en) * | 2011-12-30 | 2012-07-18 | 北京新媒传信科技有限公司 | Method and system for distributing thread execution task |
CN103197968A (en) * | 2013-03-18 | 2013-07-10 | 焦点科技股份有限公司 | Thread pool processing method and system capable of fusing synchronous and asynchronous features |
CN105159768A (en) * | 2015-09-09 | 2015-12-16 | 浪潮集团有限公司 | Task management method and cloud data center management platform |
Non-Patent Citations (1)
Title |
---|
折羽青鸟930222: ""Linux线程池"", 《百度文库》 * |
Cited By (38)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106547612A (en) * | 2016-10-18 | 2017-03-29 | 深圳怡化电脑股份有限公司 | A kind of multi-task processing method and device |
CN106547612B (en) * | 2016-10-18 | 2020-10-20 | 深圳怡化电脑股份有限公司 | Multitasking method and device |
CN106506389A (en) * | 2016-10-19 | 2017-03-15 | 广州华多网络科技有限公司 | Network request asynchronous processing method and device |
CN106648892A (en) * | 2016-12-12 | 2017-05-10 | 深圳市元征软件开发有限公司 | Allocation processing method and device for detection threads |
CN108228240B (en) * | 2016-12-14 | 2021-02-26 | 北京国双科技有限公司 | Method and device for processing tasks in multi-task queue |
CN108228240A (en) * | 2016-12-14 | 2018-06-29 | 北京国双科技有限公司 | The treating method and apparatus of task in multitask queue |
CN106648874A (en) * | 2016-12-30 | 2017-05-10 | 中国建设银行股份有限公司 | Processing method and device for batched task |
CN106648874B (en) * | 2016-12-30 | 2020-05-22 | 中国建设银行股份有限公司 | Processing method and device for batch tasks |
CN106953857A (en) * | 2017-03-16 | 2017-07-14 | 郑州云海信息技术有限公司 | A kind of server end Multithread management method based on CS frameworks |
CN107391243A (en) * | 2017-06-30 | 2017-11-24 | 广东神马搜索科技有限公司 | Thread task processing equipment, device and method |
CN108681481B (en) * | 2018-03-13 | 2021-10-15 | 创新先进技术有限公司 | Service request processing method and device |
CN108681481A (en) * | 2018-03-13 | 2018-10-19 | 阿里巴巴集团控股有限公司 | The processing method and processing device of service request |
CN108984285B (en) * | 2018-06-28 | 2021-10-15 | 上海数据交易中心有限公司 | Data collision flow analysis method and device, storage medium and terminal |
CN108984285A (en) * | 2018-06-28 | 2018-12-11 | 上海数据交易中心有限公司 | A kind of analysis of data collision flow point method and device, storage medium, terminal |
CN110750339A (en) * | 2018-07-23 | 2020-02-04 | 杭州海康威视系统技术有限公司 | Thread scheduling method and device and electronic equipment |
CN110750339B (en) * | 2018-07-23 | 2022-04-26 | 杭州海康威视系统技术有限公司 | Thread scheduling method and device and electronic equipment |
CN109388485A (en) * | 2018-09-26 | 2019-02-26 | 广州虎牙信息科技有限公司 | A kind of processing method, device, equipment and the storage medium of task execution thread |
CN111124655A (en) * | 2018-10-31 | 2020-05-08 | 武汉斗鱼网络科技有限公司 | Network request scheduling method, terminal device and storage medium |
CN109669776A (en) * | 2018-12-12 | 2019-04-23 | 北京文章无忧信息科技有限公司 | Processing method, the device and system of Detection task |
CN109669776B (en) * | 2018-12-12 | 2023-08-04 | 北京文章无忧信息科技有限公司 | Detection task processing method, device and system |
CN109815007A (en) * | 2018-12-15 | 2019-05-28 | 平安科技(深圳)有限公司 | Thread control method, device, electronic equipment and storage medium based on cloud monitoring |
CN109756565A (en) * | 2018-12-26 | 2019-05-14 | 成都科来软件有限公司 | A kind of Multitask Data method for pushing based on statistical form |
CN110321213A (en) * | 2019-07-08 | 2019-10-11 | 杭州港盛软件科技有限公司 | A kind of request processing method, device, equipment and readable storage medium storing program for executing |
CN110457124A (en) * | 2019-08-06 | 2019-11-15 | 中国工商银行股份有限公司 | For the processing method and its device of business thread, electronic equipment and medium |
CN110457126A (en) * | 2019-08-13 | 2019-11-15 | 杭州有赞科技有限公司 | A kind of asynchronous invoking method and system |
CN112395054A (en) * | 2019-08-15 | 2021-02-23 | 杭州海康威视系统技术有限公司 | Thread scheduling method, device and system |
CN110515715A (en) * | 2019-08-22 | 2019-11-29 | 北京宝兰德软件股份有限公司 | Task processing method and device based on thread pool |
CN111491015A (en) * | 2020-03-31 | 2020-08-04 | 北京金山云网络技术有限公司 | Preheating task processing method and system, proxy server and service center |
CN111767125B (en) * | 2020-06-15 | 2023-07-25 | 杭州数梦工场科技有限公司 | Task execution method, device, electronic equipment and storage medium |
CN111767125A (en) * | 2020-06-15 | 2020-10-13 | 杭州数梦工场科技有限公司 | Task execution method and device, electronic equipment and storage medium |
CN111782293A (en) * | 2020-06-28 | 2020-10-16 | 珠海豹趣科技有限公司 | Task processing method and device, electronic equipment and readable storage medium |
CN111857865A (en) * | 2020-06-28 | 2020-10-30 | 珠海豹趣科技有限公司 | Event type task processing method and device, electronic equipment and storage medium |
CN111782295A (en) * | 2020-06-29 | 2020-10-16 | 珠海豹趣科技有限公司 | Application program running method and device, electronic equipment and storage medium |
CN111782295B (en) * | 2020-06-29 | 2023-08-29 | 珠海豹趣科技有限公司 | Application program running method and device, electronic equipment and storage medium |
CN112905326A (en) * | 2021-02-18 | 2021-06-04 | 上海哔哩哔哩科技有限公司 | Task processing method and device |
CN112905326B (en) * | 2021-02-18 | 2023-04-11 | 上海哔哩哔哩科技有限公司 | Task processing method and device |
CN115037702A (en) * | 2022-05-23 | 2022-09-09 | 北京梧桐车联科技有限责任公司 | Message distribution method, data transmission method and equipment |
CN115037702B (en) * | 2022-05-23 | 2024-04-12 | 北京梧桐车联科技有限责任公司 | Message distribution and data transmission methods and equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106020954A (en) | Thread management method and device | |
US9940177B2 (en) | Traffic control method and system | |
CN110427262B (en) | Gene data analysis method and heterogeneous scheduling platform | |
CN104536827B (en) | A kind of data dispatching method and device | |
WO2017080273A1 (en) | Task management methods and system, and computer storage medium | |
US8615765B2 (en) | Dividing a computer job into micro-jobs | |
CN103365718A (en) | Thread scheduling method, thread scheduling device and multi-core processor system | |
KR20180053359A (en) | Efficient scheduling of multi-version tasks | |
CN105912386A (en) | Thread management method and system | |
US10157155B2 (en) | Operating system-managed interrupt steering in multiprocessor systems | |
US20210248469A1 (en) | Method and apparatus for scheduling deep learning reasoning engines, device, and medium | |
US11630692B2 (en) | Efficient worker utilization | |
US20130198758A1 (en) | Task distribution method and apparatus for multi-core system | |
US9383800B2 (en) | Managing a portal application | |
CN104598426A (en) | task scheduling method applied to a heterogeneous multi-core processor system | |
CN111880939A (en) | Container dynamic migration method and device and electronic equipment | |
CN104035818A (en) | Multiple-task scheduling method and device | |
US20130238547A1 (en) | Methods, Systems, and Products for Stream Warehousing | |
CN109710624B (en) | Data processing method, device, medium and electronic equipment | |
CN102033784A (en) | Method and device for optimizing application server | |
US20180191861A1 (en) | Method and Apparatus for Scheduling Resources in a Cloud System | |
CN106445686A (en) | Resource distribution method and device | |
CN107624181B (en) | Virtual machine management method and apparatus including idling and scheduling of virtual processors | |
CN113626173B (en) | Scheduling method, scheduling device and storage medium | |
GB2527081A (en) | Asynchronous resource usage collection and control of fenced user code |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
CB02 | Change of applicant information | ||
CB02 | Change of applicant information |
Address after: 518057 Shenzhen Software Park, Nanshan District high tech Industrial Park, Guangdong, China,, 6 401-402 Applicant after: Yongxing Shenzhen Polytron Technologies Inc Address before: 518057 Shenzhen Software Park, Nanshan District high tech Industrial Park, Guangdong, China,, 6 401-402 Applicant before: Shenzhen Longrise Technology Co., Ltd. |
|
RJ01 | Rejection of invention patent application after publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20161012 |