[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

CN110515713A - A kind of method for scheduling task, equipment and computer storage medium - Google Patents

A kind of method for scheduling task, equipment and computer storage medium Download PDF

Info

Publication number
CN110515713A
CN110515713A CN201910744664.1A CN201910744664A CN110515713A CN 110515713 A CN110515713 A CN 110515713A CN 201910744664 A CN201910744664 A CN 201910744664A CN 110515713 A CN110515713 A CN 110515713A
Authority
CN
China
Prior art keywords
task
thread
priority
chained list
parameter
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
CN201910744664.1A
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 Unita Information Technology Co Ltd
Original Assignee
Beijing Unita 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 Unita Information Technology Co Ltd filed Critical Beijing Unita Information Technology Co Ltd
Priority to CN201910744664.1A priority Critical patent/CN110515713A/en
Publication of CN110515713A publication Critical patent/CN110515713A/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
    • 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

Landscapes

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

Abstract

The application provides a kind of method for scheduling task, equipment and computer storage medium.This method initialization thread and structural body;Thread and structural body include at least: tick thread, asynchronous queue, chained list, thread pool main body thread;Tick thread, for doing counting processing, with the determination in auxiliary dispatching period;Asynchronous queue is the aggregate that multiple Thread Communications share message;Chained list is the aggregate where task individual;Thread pool main body thread is the manual operation main body of task in operation;Task is added into resource pool and the parameter of task is set;The parameter of task includes at least: priority, and timeslice uses duration, task attribute;Task attribute is serial, alternatively, parallel;According to the thread and structural body after initialization, the parameter scheduler task of task.The scheduling for carrying out task in scheme provided by the present application according to the parameter of task, for the different task parameters of different scene settings, so that this programme is suitable for multiple scenes.

Description

A kind of method for scheduling task, equipment and computer storage medium
Technical field
The present invention relates to field of computer technology more particularly to a kind of method for scheduling task, equipment and computer storage to be situated between Matter.
Background technique
In program operation, when having high concurrent access and task quickly to handle, the creation of thread, switching, when destruction is non- System resource is often consumed, because one thread of creation will obtain memory source or other more resources.So improving service One means of program efficiency are exactly to reduce the number of creation and destroying threads as far as possible, especially paroxysmal a large amount of in receiving Request, it is unlikely to make server therefore generate a large amount of threads and make program run quickly and burst.How using existing object to be exactly to service One critical issue for needing to solve.
Summary of the invention
To solve the above problems, the embodiment of the present application provides a kind of method for scheduling task, which comprises
Initialization thread and structural body;The thread and structural body include at least: tick thread, asynchronous queue, chained list, thread pool Main body thread;The tick thread, for doing counting processing, with the determination in auxiliary dispatching period;The asynchronous queue is multiple Thread Communication shares the aggregate of message;The chained list is the aggregate where task individual;The thread pool main body thread is The manual operation main body of task in operation;
Task is added into resource pool and the parameter of the task is set;Wherein, the parameter of task includes at least: priority, when Between piece use duration, task attribute;The task attribute is serial, alternatively, parallel;
According to the thread and structural body after initialization, the parameter of task dispatches the task.
Optionally, the parameter of the thread and structural body according to after initialization, task dispatches the task, comprising:
N task is selected from asynchronous queue and/or resource pool, wherein n is the quantity of thread pool main body thread;
When chained list is empty, n task is added in the chained list, each task is exclusive in chained list within a dispatching cycle One thread, by task suspension each in chained list, sets NEXT for the state of task each in chained list after dispatching cycle, So that untreated complete task continues to execute in next dispatching cycle in chained list;
When chained list non-empty, n task is added to asynchronous queue.
Optionally, after task being added in asynchronous queue, further includes:
If the task execution being added in asynchronous queue finishes, EXIT is set by its state, thread is exited and destroys.
It is optionally, described that n task is selected from asynchronous queue and/or resource pool, comprising:
By all tasks in asynchronous queue and resource pool, n task is selected from high to low according to priority.
It is optionally, described to select n task from high to low according to priority, comprising:
Determine hanging up for task;
Service attribute is the task of serial hang-up if it exists, then selects service attribute for the task of serial hang-up;
In the task of non-hang-up, n-m task is selected from high to low according to priority;
Wherein, m is the task quantity that service attribute is serial hang-up.
Optionally, when selecting task from high to low according to priority, there are multiple tasks for priority if they are the same, then according to puppet Random number determines the random chance of each task of same priority;It is selected from the task of same priority from big to small according to random chance Select task.
Optionally, when selecting task from high to low according to priority, each task is determined according to pseudo random number and priority Random chance, so that the random chance of different priorities is different;Task is selected from big to small according to random chance.
Optionally, priority is one of 0 to 7 grade;
The priority of 0 grade to 7 grades successively reduces.
In order to achieve the above object, the main technical schemes that the present invention uses further include:
A kind of electronic equipment can be run on a memory and on a processor including memory, processor, bus and storage Computer program, the processor are realized when executing described program such as the step of above method any one.
In order to achieve the above object, the main technical schemes that the present invention uses further include:
A kind of computer storage medium is stored thereon with computer program, realizes when described program is executed by processor as above-mentioned The step of method any one.
It has the beneficial effect that:
The application initialization thread and structural body;Thread and structural body include at least: tick thread, asynchronous queue, chained list, thread Tank main body thread;Tick thread, for doing counting processing, with the determination in auxiliary dispatching period;Asynchronous queue is logical for multiple threads Interrogate the aggregate of shared message;Chained list is the aggregate where task individual;Thread pool main body thread is that task is practical in operation The operation main body occupied;Task is added into resource pool and the parameter of task is set;The parameter of task includes at least: priority, Timeslice uses duration, task attribute;Task attribute is serial, alternatively, parallel;According to the thread and structural body after initialization, The parameter scheduler task of task.The scheduling that task is carried out according to the parameter of task, for the different task of different scene settings Parameter, so that this programme is suitable for multiple scenes.
Detailed description of the invention
The specific embodiment of the application is described below with reference to accompanying drawings, in which:
Fig. 1 shows a kind of flow diagram of method for scheduling task of one embodiment of the application offer;
Fig. 2 shows the flow diagrams for another method for scheduling task that one embodiment of the application provides;
Fig. 3 shows the structural schematic diagram of a kind of electronic equipment of one embodiment of the application offer.
Specific embodiment
In program operation, when having high concurrent access and task quickly to handle, the creation of thread, switching, when destruction is non- System resource is often consumed, because one thread of creation will obtain memory source or other more resources.So improving service One means of program efficiency are exactly to reduce the number of creation and destroying threads as far as possible, especially paroxysmal a large amount of in receiving Request, it is unlikely to make server therefore generate a large amount of threads and make program run quickly and burst.How using existing object to be exactly to service One critical issue for needing to solve.
Based on this, the present invention provides a kind of method for scheduling task, this method initialization thread and structural body;Thread and structure Body includes at least: tick thread, asynchronous queue, chained list, thread pool main body thread;Tick thread, for doing counting processing, with auxiliary The determination in auxiliary dispatch period;Asynchronous queue is the aggregate that multiple Thread Communications share message;Chained list is task individual place Aggregate;Thread pool main body thread is the manual operation main body of task in operation;Task is added into resource pool and is arranged The parameter of task;The parameter of task includes at least: priority, and timeslice uses duration, task attribute;Task attribute be it is serial, Alternatively, parallel;According to the thread and structural body after initialization, the parameter scheduler task of task.Due to according to the parameter of task into The scheduling of row task, for the different task parameters of different scene settings, so that this programme is suitable for multiple scenes.
Referring to Fig. 1, the implementation of method for scheduling task provided by the invention is described in detail.
101, initialization thread and structural body.
Wherein, thread and structural body include at least: tick thread, asynchronous queue, chained list, thread pool main body thread.
Tick thread, for doing counting processing, with the determination in auxiliary dispatching period.
Asynchronous queue is the aggregate that multiple Thread Communications share message.
Chained list is the aggregate where task individual.
Thread pool main body thread is the manual operation main body of task in operation.
102, task is added into resource pool and the parameter of task is set.
Wherein, the parameter of task includes at least: priority, and timeslice uses duration, task attribute.Task attribute is string Row, alternatively, parallel.
Priority is one of 0 to 7 grade.The priority of 0 grade to 7 grades successively reduces.
103, according to the thread and structural body after initialization, the parameter scheduler task of task.
Specifically, this step is achieved by the steps of:
1, n task is selected from asynchronous queue and/or resource pool.
Wherein n is the quantity of thread pool main body thread.
A method of selecting n task from asynchronous queue and/or resource pool are as follows: will be in asynchronous queue and resource pool All tasks select n task according to priority from high to low.
Another kind selects the mode of n task from asynchronous queue and/or resource pool are as follows: 1) in asynchronous queue and resource pool In all tasks in, determine hang up task.2) service attribute is the task of serial hang-up if it exists, then selects business category Property be serial hang-up task.3) in the task of non-hang-up, n-m task is selected from high to low according to priority.
Wherein, m is the task quantity that service attribute is serial hang-up.
It either selects n task from high to low according to priority, still, selects n-m from high to low according to priority Task is to select task from high to low according to priority, and the quantity being simply to select is different.
When selecting task from high to low according to priority, appointing for 0 grade of priority first can be selected according to the priority Business, if the quantity of selection is had not been met, then selecting the task of 1 grade of priority again after the task of all 0 grade of priority of selection.If 1 The task quantity of grade priority is more than the quantity to be selected, then do not select the task of 1 grade of all priority, but from 1 Selection meets the task of quantity in the task of grade priority.Selection meets the side of the task of quantity from the task of 1 grade of priority There are many methods, such as random choosing, and there are multiple tasks for priority if they are the same for another example, then determine same priority according to pseudo random number The random chance of each task selects task from the task of same priority from big to small according to random chance.
When selecting task from high to low according to priority, in addition to the method described above, it is also an option that following mode: The random chance of each task is determined according to pseudo random number and priority so that the random chance of different priorities is different, according to Machine probability selects task from big to small.
It may insure that the scheduling probability of task tends to be equal by pseudo random number, operation duration is equal.
2, when chained list is empty, n task is added in chained list, each task is only in chained list within a dispatching cycle Account for a thread, after dispatching cycle, 1) by task suspension each in chained list, 2) it sets the state of task each in chained list to NEXT, 3) task each in chained list is added in asynchronous queue, so that untreated complete task is in next scheduling week in chained list Phase continues to execute.
3, when chained list non-empty, n task is added to asynchronous queue, to wait scheduling next time.
In addition, whether also the judging addition asynchronous queue of the task executes after having task to be added to asynchronous queue It finishes, if the task execution being added in asynchronous queue finishes, sets EXIT for its state, exit thread and destroy.If not It is finished, then waits scheduling next time.
Referring to fig. 2, above-mentioned method for scheduling task provided in this embodiment, some threads and data knot that can be pre-created Structure, such as have following sections:
1. tick thread, for doing counting processing, the reference basis of dispatching cycle.
2. asynchronous queue, it is fit that multiple Thread Communications share message set.
3. chained list, the aggregate where task individual.
4. thread pool main body thread, the manual operation main body of task in operation
Above-mentioned method for scheduling task when in use, initializes above-mentioned thread and structural body first.Secondly, addition task, is adding The priority of task can be arranged according to concrete scene when adding for task, it is serial or parallel that timeslice, which uses duration, Task dispatching task parameters.Then, according to the thread and structural body after initialization, the parameter scheduler task of task.
For example, the method for scheduling task provided through this embodiment is all the same to priority, task attribute is concurrent The implementation that multiple tasks are scheduled are as follows: task is in initial state, in the case where chained list is empty, newly added task It is preferential to execute, in timeslice, monopolize a thread, timeslice terminates, and task suspension, task status is set to NEXT, then plus Enter the scheduling waited to asynchronous schedule queue next time.
If chained list be not it is empty, be added in asynchronous queue, task is in scheduling strategy, and a possibility that being dispatched to is according to puppet The random chance of random number is dispatched.It is dispatched to, is run within a cycle of operation, be not carried out task and then waited next time Scheduling.If being added in asynchronous queue for task is performed, the state for setting task is NEXT, and task exits thread pool, and sells Ruin task.When number of tasks is more than maximum scheduling number, it is added to task waiting list.
Method provided in this embodiment has drawn 8 etc. to guarantee that important task is preferentially executed in terms of task grade Grade, priority level successively reduces from 0 to 7.0 level priority highest, 7 level priorities are minimum.8 grades, each grade quilt The probability being dispatched to is different.High priority, in scheduling, priority scheduling is fallen out.
If task is provided with serial attribute, after the completion of having to wait for task execution, next task can be just executed.
Task is with priority, the task attributes such as serial parallel to method provided in this embodiment in operation.Use state Machine technology can allow task efficiently to execute in thread pool.Taken into account while guaranteeing high concurrent task particular task it is long when Between run.Using pseudo random number, under equal priority, the probability being dispatched to is almost the same, different priorities, and what is be dispatched to is general Rate is different.Running task status can quickly be hit by thread main body.
Example 1,
Below by taking the scheduling of serial task as an example, method provided in this embodiment is illustrated.
The scheduling of serial task in this example is must can just to run next tune until current task end of run The task of degree, this dispatching method,
Necessary structural body needed for 1-1) creating thread pool, variable, thread main body Thread Count are 5.
10 big file (1GB) transformation task (abbreviation task A0 ~ A9) 1-2) is created, task grade is 3, is then being created 5 big file (1GB) transmits (abbreviation task B0 ~ B4), and task grade is 1.
1-3) task A0 ~ A9 is added in thread pool, and after running 10s, discovery is sent under the transmission catalogue of task A0 ~ A4 5 files, but all without end of transmission.
1-4) task B is added in thread pool.
1-5) judge task A0 ~ A4 whether end of transmission, be illustrate scheduling meet serial design requirement, then follow the steps 1-6), otherwise terminate to dispatch.
After the file end of transmission for 1-6) judging task A0 ~ A4, if the file of transformation task B0 ~ B4.If then illustrating Task priority has effect, and scheduling continues down, to execute step 1-7).If not then task schedule fails, this scheduling is exited Method.
1-7) the task continuous transmission of task B0 ~ B4, until five file end of transmissions.
It 1-8) is then restored to task A5 ~ A9, file starts to transmit.Until the All Files of task A5 ~ A9 all transmit It finishes.
Example 2,
Below by taking the scheduling of parallel task as an example, method provided in this embodiment is illustrated.
The scheduling of parallel task in this example refers to that multiplexed transport is can not have to terminate until previous task schedule, directly Connect the method for opening next task schedule.JMeter can be used to be tested, small documents test also can be used, this example is used Small documents test
Necessary structural body needed for 2-1) creating thread pool, variable, thread main body Thread Count are 5.
2-2) create the 1KB small documents of 50w.
2-3) use file multiplexed transport tool.Start to transmit.Each small documents open a socket connection, and 50w is small File is equivalent to 50w socket connection.
2-4) in task schedule, the priority of each task is consistent, each dispatching cycle (abbreviation timeslice) of scheduling 1000 tasks.
2-5) idle task is added to task waiting list.1000 task numbers of scheduling every time, judge the discrete of task number Situation exits scheduling if continuously, then dispatching and failing.Task number is discrete, meets design, the basic phase of probability that task obtains When.
2-6) since file is small, it can handle and be in a dispatching cycle, substantially be seen with netstat-nat Socket connection number is held at 1000 or so.
Example 3,
Below for being suitble to the test of scene, method provided in this embodiment is illustrated.
This example is to examine the versatility of thread pool scheduling.Above-mentioned two example (scheduling of 1 serial task of example, example 2 The scheduling of parallel task) demonstrate file transmission and socket concurrent transmission.The application scenarios of this example validation database connection.
Necessary structural body needed for 3-1) creating thread pool, variable, thread main body Thread Count are 5.
3-2) creation database connection task, including mysql, oracle, sqlserver etc.
3-3) in order to guarantee that per thread has task, each database all plays five tasks when adding database tasks.
3-4) check connection status, connection normally continues to execute step 5), otherwise exits dispatching method.
Mass data 3-5) is read, the data volume of single table is in million grades or millions.It is fast to read data speed.
3-6) three kinds of database tasks stable operation.
This illustrates that this dispatching method is suitable for database and connects scene.
Method provided in this embodiment under the scenes such as stringent execution sequence, solves existing with different task grade There is Thread Pool Technology without task priority, the case where being all uniformly processed.In addition, method provided in this embodiment is suitable for multiple Scene, all scenes only need to modify necessary task parameters.High concurrent scene only needs priority consistent, and task is parallel appoints Business;Different priority is arranged in vital task;The task of stringent sequencing, can be consistent with priority, and task is serial Task.In addition, method provided in this embodiment can achieve the rate of single thread processing individual task.
The utility model has the advantages that
Initialization thread and structural body;Thread and structural body include at least: tick thread, asynchronous queue, chained list, thread tank main body Thread;Tick thread, for doing counting processing, with the determination in auxiliary dispatching period;Asynchronous queue is shared for multiple Thread Communications The aggregate of message;Chained list is the aggregate where task individual;Thread pool main body thread is that task is manual in operation Run main body;Task is added into resource pool and the parameter of task is set;The parameter of task includes at least: priority, timeslice Use duration, task attribute;Task attribute is serial, alternatively, parallel;According to the thread and structural body after initialization, task Parameter scheduler task.Made according to the scheduling that the parameter of task carries out task for the different task parameters of different scene settings It obtains this programme and is suitable for multiple scenes.
Referring to Fig. 3, a kind of electronic equipment is present embodiments provided, which includes: memory 301, processor 302, bus 303 and it is stored in the computer program that can be run on memory 301 and on processor 302.
The processor 302 realizes following method when executing described program:
Initialization thread and structural body;Thread and structural body include at least: tick thread, asynchronous queue, chained list, thread tank main body Thread;Tick thread, for doing counting processing, with the determination in auxiliary dispatching period;Asynchronous queue is shared for multiple Thread Communications The aggregate of message;Chained list is the aggregate where task individual;Thread pool main body thread is that task is manual in operation Run main body;
Task is added into resource pool and the parameter of task is set;Wherein, the parameter of task includes at least: priority, timeslice Use duration, task attribute;Task attribute is serial, alternatively, parallel;
According to the thread and structural body after initialization, the parameter scheduler task of task.
Optionally, according to the thread and structural body after initialization, the parameter scheduler task of task, comprising:
N task is selected from asynchronous queue and/or resource pool, wherein n is the quantity of thread pool main body thread;
When chained list is empty, n task is added in chained list, each task is one exclusive in chained list within a dispatching cycle Thread, by task suspension each in chained list, sets NEXT for the state of task each in chained list after dispatching cycle, so that Untreated complete task continues to execute in next dispatching cycle in chained list;
When chained list non-empty, n task is added to asynchronous queue.
Optionally, after task being added in asynchronous queue, further includes:
If the task execution being added in asynchronous queue finishes, EXIT is set by its state, thread is exited and destroys.
Optionally, n task is selected from asynchronous queue and/or resource pool, comprising:
By all tasks in asynchronous queue and resource pool, n task is selected from high to low according to priority.
Optionally, n task is selected from high to low according to priority, comprising:
Determine hanging up for task;
Service attribute is the task of serial hang-up if it exists, then selects service attribute for the task of serial hang-up;
In the task of non-hang-up, n-m task is selected from high to low according to priority;
Wherein, m is the task quantity that service attribute is serial hang-up.
Optionally, when selecting task from high to low according to priority, there are multiple tasks for priority if they are the same, then according to puppet Random number determines the random chance of each task of same priority;It is selected from the task of same priority from big to small according to random chance Select task.
Optionally, when selecting task from high to low according to priority, each task is determined according to pseudo random number and priority Random chance, so that the random chance of different priorities is different;Task is selected from big to small according to random chance.
Optionally, priority is one of 0 to 7 grade;
The priority of 0 grade to 7 grades successively reduces.
Electronic equipment provided in this embodiment, initialization thread and structural body;Thread and structural body include at least: tick line Journey, asynchronous queue, chained list, thread pool main body thread;Tick thread, for doing counting processing, with the determination in auxiliary dispatching period; Asynchronous queue is the aggregate that multiple Thread Communications share message;Chained list is the aggregate where task individual;Thread tank main body Thread is the manual operation main body of task in operation;Task is added into resource pool and the parameter of task is set;Task Parameter includes at least: priority, and timeslice uses duration, task attribute;Task attribute is serial, alternatively, parallel;According to initial Thread and structural body after change, the parameter scheduler task of task.The scheduling that task is carried out according to the parameter of task, for different The different task parameters of scene setting, so that this programme is suitable for multiple scenes.
A kind of computer storage medium is present embodiments provided, which performs the following operations:
Initialization thread and structural body;Thread and structural body include at least: tick thread, asynchronous queue, chained list, thread tank main body Thread;Tick thread, for doing counting processing, with the determination in auxiliary dispatching period;Asynchronous queue is shared for multiple Thread Communications The aggregate of message;Chained list is the aggregate where task individual;Thread pool main body thread is that task is manual in operation Run main body;
Task is added into resource pool and the parameter of task is set;Wherein, the parameter of task includes at least: priority, timeslice Use duration, task attribute;Task attribute is serial, alternatively, parallel;
According to the thread and structural body after initialization, the parameter scheduler task of task.
Optionally, according to the thread and structural body after initialization, the parameter scheduler task of task, comprising:
N task is selected from asynchronous queue and/or resource pool, wherein n is the quantity of thread pool main body thread;
When chained list is empty, n task is added in chained list, each task is one exclusive in chained list within a dispatching cycle Thread, by task suspension each in chained list, sets NEXT for the state of task each in chained list after dispatching cycle, so that Untreated complete task continues to execute in next dispatching cycle in chained list;
When chained list non-empty, n task is added to asynchronous queue.
Optionally, after task being added in asynchronous queue, further includes:
If the task execution being added in asynchronous queue finishes, EXIT is set by its state, thread is exited and destroys.
Optionally, n task is selected from asynchronous queue and/or resource pool, comprising:
By all tasks in asynchronous queue and resource pool, n task is selected from high to low according to priority.
Optionally, n task is selected from high to low according to priority, comprising:
Determine hanging up for task;
Service attribute is the task of serial hang-up if it exists, then selects service attribute for the task of serial hang-up;
In the task of non-hang-up, n-m task is selected from high to low according to priority;
Wherein, m is the task quantity that service attribute is serial hang-up.
Optionally, when selecting task from high to low according to priority, there are multiple tasks for priority if they are the same, then according to puppet Random number determines the random chance of each task of same priority;It is selected from the task of same priority from big to small according to random chance Select task.
Optionally, when selecting task from high to low according to priority, each task is determined according to pseudo random number and priority Random chance, so that the random chance of different priorities is different;Task is selected from big to small according to random chance.
Optionally, priority is one of 0 to 7 grade;
The priority of 0 grade to 7 grades successively reduces.
Computer storage medium provided in this embodiment, initialization thread and structural body;Thread and structural body include at least: Tick thread, asynchronous queue, chained list, thread pool main body thread;Tick thread, for doing counting processing, with the auxiliary dispatching period Determination;Asynchronous queue is the aggregate that multiple Thread Communications share message;Chained list is the aggregate where task individual;Thread Tank main body thread is the manual operation main body of task in operation;Task is added into resource pool and the parameter of task is set; The parameter of task includes at least: priority, and timeslice uses duration, task attribute;Task attribute is serial, alternatively, parallel;Root According to the thread and structural body after initialization, the parameter scheduler task of task.The scheduling that task is carried out according to the parameter of task, for The different task parameters of different scene settings, so that this programme is suitable for multiple scenes.

Claims (10)

1. a kind of method for scheduling task, which is characterized in that the described method includes:
Initialization thread and structural body;The thread and structural body include at least: tick thread, asynchronous queue, chained list, thread pool Main body thread;The tick thread, for doing counting processing, with the determination in auxiliary dispatching period;The asynchronous queue is multiple Thread Communication shares the aggregate of message;The chained list is the aggregate where task individual;The thread pool main body thread is The manual operation main body of task in operation;
Task is added into resource pool and the parameter of the task is set;Wherein, the parameter of task includes at least: priority, when Between piece use duration, task attribute;The task attribute is serial, alternatively, parallel;
According to the thread and structural body after initialization, the parameter of task dispatches the task.
2. the method according to claim 1, wherein the thread and structural body according to after initialization, task Parameter dispatch the task, comprising:
N task is selected from asynchronous queue and/or resource pool, wherein n is the quantity of thread pool main body thread;
When chained list is empty, n task is added in the chained list, each task is exclusive in chained list within a dispatching cycle One thread, by task suspension each in chained list, sets NEXT for the state of task each in chained list after dispatching cycle, So that untreated complete task continues to execute in next dispatching cycle in chained list;
When chained list non-empty, n task is added to asynchronous queue.
3. according to the method described in claim 2, it is characterized in that, after task is added in asynchronous queue, further includes:
If the task execution being added in asynchronous queue finishes, EXIT is set by its state, thread is exited and destroys.
4. according to the method described in claim 3, it is characterized in that, described select n from asynchronous queue and/or resource pool Business, comprising:
By all tasks in asynchronous queue and resource pool, n task is selected from high to low according to priority.
5. according to the method described in claim 4, it is characterized in that, described select n task, packet according to priority from high to low It includes:
Determine hanging up for task;
Service attribute is the task of serial hang-up if it exists, then selects service attribute for the task of serial hang-up;
In the task of non-hang-up, n-m task is selected from high to low according to priority;
Wherein, m is the task quantity that service attribute is serial hang-up.
6. according to the method described in claim 5, it is characterized in that, when selecting task from high to low according to priority, if they are the same There are multiple tasks for priority, then the random chance of each task of same priority is determined according to pseudo random number;According to random chance Task is selected from the task of same priority from big to small.
7. according to the method described in claim 5, it is characterized in that, when selecting task from high to low according to priority, according to puppet Random number and priority determine the random chance of each task, so that the random chance of different priorities is different;According to random chance Task is selected from big to small.
8. method according to claim 6 or 7, which is characterized in that priority is one of 0 to 7 grade;
The priority of 0 grade to 7 grades successively reduces.
9. a kind of electronic equipment, which is characterized in that on a memory and can be including memory, processor, bus and storage The computer program run on processor, the processor are realized when executing described program such as claim 1-8 any one Method.
10. a kind of computer storage medium, is stored thereon with computer program, it is characterised in that: described program is held by processor The method such as claim 1-8 any one is realized when row.
CN201910744664.1A 2019-08-13 2019-08-13 A kind of method for scheduling task, equipment and computer storage medium Pending CN110515713A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910744664.1A CN110515713A (en) 2019-08-13 2019-08-13 A kind of method for scheduling task, equipment and computer storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910744664.1A CN110515713A (en) 2019-08-13 2019-08-13 A kind of method for scheduling task, equipment and computer storage medium

Publications (1)

Publication Number Publication Date
CN110515713A true CN110515713A (en) 2019-11-29

Family

ID=68624811

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910744664.1A Pending CN110515713A (en) 2019-08-13 2019-08-13 A kind of method for scheduling task, equipment and computer storage medium

Country Status (1)

Country Link
CN (1) CN110515713A (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111240762A (en) * 2020-01-10 2020-06-05 珠海格力电器股份有限公司 Thread management method, storage medium and electronic device
CN111400010A (en) * 2020-03-18 2020-07-10 中国建设银行股份有限公司 Task scheduling method and device
CN111880915A (en) * 2020-07-24 2020-11-03 北京浪潮数据技术有限公司 Method, device and equipment for processing thread task and storage medium
CN111930486A (en) * 2020-07-30 2020-11-13 中国工商银行股份有限公司 Task selection data processing method, device, equipment and storage medium
CN114816748A (en) * 2022-04-22 2022-07-29 北京达佳互联信息技术有限公司 Thread scheduling method and device, electronic equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103345385A (en) * 2013-07-29 2013-10-09 北京汉邦高科数字技术股份有限公司 Method for converting serial events into parallel events
CN104111877A (en) * 2014-07-29 2014-10-22 广东能龙教育股份有限公司 Thread dynamic deployment system and method based on thread deployment engine
US9256623B2 (en) * 2013-05-08 2016-02-09 Nvidia Corporation System, method, and computer program product for scheduling tasks associated with continuation thread blocks
CN108595282A (en) * 2018-05-02 2018-09-28 广州市巨硅信息科技有限公司 A kind of implementation method of high concurrent message queue

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9256623B2 (en) * 2013-05-08 2016-02-09 Nvidia Corporation System, method, and computer program product for scheduling tasks associated with continuation thread blocks
CN103345385A (en) * 2013-07-29 2013-10-09 北京汉邦高科数字技术股份有限公司 Method for converting serial events into parallel events
CN104111877A (en) * 2014-07-29 2014-10-22 广东能龙教育股份有限公司 Thread dynamic deployment system and method based on thread deployment engine
CN108595282A (en) * 2018-05-02 2018-09-28 广州市巨硅信息科技有限公司 A kind of implementation method of high concurrent message queue

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111240762A (en) * 2020-01-10 2020-06-05 珠海格力电器股份有限公司 Thread management method, storage medium and electronic device
CN111400010A (en) * 2020-03-18 2020-07-10 中国建设银行股份有限公司 Task scheduling method and device
CN111880915A (en) * 2020-07-24 2020-11-03 北京浪潮数据技术有限公司 Method, device and equipment for processing thread task and storage medium
CN111880915B (en) * 2020-07-24 2023-07-21 北京浪潮数据技术有限公司 Processing method, device, equipment and storage medium for thread task
CN111930486A (en) * 2020-07-30 2020-11-13 中国工商银行股份有限公司 Task selection data processing method, device, equipment and storage medium
CN111930486B (en) * 2020-07-30 2023-11-17 中国工商银行股份有限公司 Task selection data processing method, device, equipment and storage medium
CN114816748A (en) * 2022-04-22 2022-07-29 北京达佳互联信息技术有限公司 Thread scheduling method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN110515713A (en) A kind of method for scheduling task, equipment and computer storage medium
CN104750543B (en) Thread creation method, service request processing method and relevant device
JP3678414B2 (en) Multiprocessor system
CN103412786B (en) High performance server architecture system and data processing method thereof
CN113238838A (en) Task scheduling method and device and computer readable storage medium
US20040158831A1 (en) Process scheduling appratus, process scheduling method, program for process scheduling, and storage medium recording a program for process scheduling
CN110489217A (en) A kind of method for scheduling task and system
CN105892996A (en) Assembly line work method and apparatus for batch data processing
CN106598705A (en) Asynchronous task scheduling method, device and system and electronic equipment
CN105160570A (en) Concurrent online transaction processing method capable of being horizontally expanded
WO2021180092A1 (en) Task dispatching method and apparatus
WO2010135926A1 (en) Method and device for scheduling queues based on chained list
CN110908782B (en) Genetic algorithm optimization-based packaging type distributed job task scheduling method and system
CN107341041B (en) Cloud task multidimensional constraint backfill scheduling method based on priority queue
CN105373426B (en) A kind of car networking memory aware real time job dispatching method based on Hadoop
US20090070766A1 (en) Dynamic workload balancing in a thread pool
CN108170758A (en) High concurrent date storage method and computer readable storage medium
US8090903B2 (en) Fair and dynamic disk input/output bandwidth distribution
CN113961341A (en) Concurrent data processing method, system, device and storage medium based on Actor model
CN110764887A (en) Task rescheduling method and system, and related equipment and device
CN113687931A (en) Task processing method, system and device
CN113472893B (en) Data processing method, device, computing equipment and computer storage medium
Shu-Jun et al. Optimization and research of hadoop platform based on fifo scheduler
CN106775975A (en) Process scheduling method and device
CN105955816A (en) Event scheduling method and device

Legal Events

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

Application publication date: 20191129

RJ01 Rejection of invention patent application after publication