CN101887361A - Method for efficiently processing delayed tasks under multi-thread environment - Google Patents

Method for efficiently processing delayed tasks under multi-thread environment Download PDF

Info

Publication number
CN101887361A
CN101887361A CN2009100840910A CN200910084091A CN101887361A CN 101887361 A CN101887361 A CN 101887361A CN 2009100840910 A CN2009100840910 A CN 2009100840910A CN 200910084091 A CN200910084091 A CN 200910084091A CN 101887361 A CN101887361 A CN 101887361A
Authority
CN
China
Prior art keywords
task
tasks
execute
list
task list
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
CN2009100840910A
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.)
HUIXIONG (BEIJING) TECHNOLOGY Co Ltd
Original Assignee
HUIXIONG (BEIJING) 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 HUIXIONG (BEIJING) TECHNOLOGY Co Ltd filed Critical HUIXIONG (BEIJING) TECHNOLOGY Co Ltd
Priority to CN2009100840910A priority Critical patent/CN101887361A/en
Publication of CN101887361A publication Critical patent/CN101887361A/en
Pending legal-status Critical Current

Links

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a method for efficiently processing delayed tasks under the multi-thread environment, which comprises that: one class is taken as a base class of all tasks, and other concrete delayed tasks succeed the base class; when a program is started, a task list processor is initialized, which comprises a to-be-processed task list, and after all timed tasks are initialized, all the timed tasks are added into the task list to wait for execution; when an application program is started, a task dispatcher is initialized; when the application wants to execute a delay to a task to be executed at a certain time point, a concrete task object succeeding the task base class and rewriting an Execute () method is initialized, and the task is added to the task list by an AddDuty method of the task list processor; and finally, the task dispatcher executes the Execute () method of the task list processor at short intervals. Through the method, the delayed tasks can be executed under the multi-thread complex environment.

Description

A kind of method of under multi-thread environment, efficiently handling delayed tasks
Technical field
The present invention relates to a kind of under multi-thread environment the efficient method of handling delayed tasks, particularly a kind of use C# (C# be Microsoft's issue a kind of OO, run on the high-level programming language on the .NET Framework.It has comprised such as single succession, interface, with the almost same grammer of Java be compiled into the process that intermediate code is reruned, has been the leading role of the .NET windows of Microsoft network frame.) technology efficient method of handling delayed tasks under multi-thread environment.
Background technology
The service routine that operates under the multi-thread environment is generally much complicated than single-threaded because need in this case to shared resource synchronously.And .Net itself provides thread pool, this is when improving efficiency of service, also having increased the complicacy of exploitation to a certain extent, is the decision of .Net thread pool because which thread user's request is specifically distributed to, and the developer can not determine new user's request will by which thread process.
If general wanting allows thread carry out after a while again, can adopt the Thread.Sleep method, the method will be waken up execution again to reach the purpose of time-delay after will allowing thread silence for a moment.Though the method is simple; but may influence other users; use a server thread Processing tasks simultaneously because may have a plurality of clients; server rashly certain thread Sleep; may make other use the request of the client of this thread process task also to be suspended, this can influence user experience even programmed logic is taken place chaotic usually greatly.
Summary of the invention
Technical matters to be solved by this invention provides a kind of under multi-thread environment, use with user thread independently the clock thread trigger timed task, making the processed method that task that time-delay carries out can stability and high efficiency.
A kind of method of under multi-thread environment, efficiently handling delayed tasks of the present invention, this method comprises following step at least:
Step 1: with the base class of a class as all tasks, other concrete delayed tasks must be inherited this base class.This type of has attribute a: ExecuteTime to represent the time that task is performed, and has empty method a: Execute () to be used for by after having arrived task execution time, carries out concrete operations;
Step 2: during program start, task list processor of initialization at first, it comprises a to-be-processed task list, and all timed tasks are after initialization is good, and it is medium pending to add this task list.This processor has two method: Execute () and AddDuty (Duty duty), previous method be used for the executing the task task of tabulation the inside, and a back method is used for specific tasks are added to task list;
Step 3: when application program launching, task dispatcher of initialization, it comprises a clock: the Timer object, it excited once every a bit of time, the Execute () method of the list object of executing the task;
Step 4: when application is wanted to carry out the task of the execution sometime of delaying time, must one of initialization have inherited the task base class and rewritten the specific tasks object of Execute () method, by AddDuty (Duty duty) method of task list processor task has been added in the task list then;
Step 5: a bit of time of every mistake, can execute the task the Execute () method of list processor of task dispatcher, the method is taken out all task objects in order, judges the execution time, if between carrying out>current time, then carry out the Execute () method of this task object;
A kind of method of under multi-thread environment, efficiently handling delayed tasks that the present invention relates to, make under the complex environment of multithreading, the task that time-delay is carried out can be carried out, because the clock thread can be not shared with any one client-requested, so when it carries out timed task, can not impact to the Any user request.
Embodiment
Key step of the present invention is as follows:
Step 1: with the base class of a class as all tasks, other concrete delayed tasks must be inherited this base class;
Step 2: during program start, task list processor of initialization at first, it comprises a to-be-processed task list, and all timed tasks are after initialization is good, and it is medium pending to add this task list;
Step 3: when application program launching, task dispatcher of initialization, it excited once every a bit of time, the Execute () method of the list object of executing the task;
Step 4: when application is wanted to carry out the task of the execution sometime of delaying time, must one of initialization have inherited the task base class and rewritten the specific tasks object of Execute () method, by AddDuty (Duty duty) method of task list processor task has been added in the task list then;
Step 5: a bit of time of every mistake, can execute the task the Execute () method of list processor of task dispatcher, the method is taken out all task objects in order, judges the execution time, if between carrying out>current time, then carry out the Execute () method of this task object;
When above-mentioned technical scheme is implemented, initialization task and specifically execute the task and realized loose coupling, this has increased the extensibility of timed task system greatly, in addition, because use independent clock thread to come regularly triggering task, make the execution stability and high efficiency more of under the complex environment of multithreading timed task, even the shared thread of a plurality of clients is arranged, when carrying out timed task, existing Any user thread can not be affected.
It should be noted last that above embodiment is only in order to explanation and unrestricted technical scheme described in the invention; Therefore, although this instructions has been described in detail the present invention with reference to the above embodiments,, those of ordinary skill in the art should be appreciated that still and can make amendment or replacement to the present invention with being equal to; And all do not break away from the technical scheme and the improvement thereof of the spirit and scope of the present invention, and it all should be encompassed in the middle of the claim scope of the present invention.

Claims (1)

1. efficient method of handling delayed tasks under multi-thread environment, it is characterized in that: this method comprises following step at least:
Step 1: with the base class of a class as all tasks, other concrete delayed tasks must be inherited this base class.
Step 2: during program start, task list processor of initialization at first, it comprises a to-be-processed task list, and all timed tasks are after initialization is good, and it is medium pending to add this task list.
Step 3: when application program launching, task dispatcher of initialization, it comprises a clock: the Timer object, it excited once every a bit of time, the Execute () method of the list object of executing the task.
Step 4: when application is wanted to carry out the task of the execution sometime of delaying time, must one of initialization have inherited the task base class and rewritten the specific tasks object of Execute () method, by the AddDuty method of task list processor task has been added in the task list then.
Step 5: a bit of time of every mistake, can execute the task the Execute () method of list processor of task dispatcher, the method is taken out all task objects in order, judges the execution time, if between carrying out>current time, then carry out the Execute () method of this task object.
CN2009100840910A 2009-05-14 2009-05-14 Method for efficiently processing delayed tasks under multi-thread environment Pending CN101887361A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2009100840910A CN101887361A (en) 2009-05-14 2009-05-14 Method for efficiently processing delayed tasks under multi-thread environment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2009100840910A CN101887361A (en) 2009-05-14 2009-05-14 Method for efficiently processing delayed tasks under multi-thread environment

Publications (1)

Publication Number Publication Date
CN101887361A true CN101887361A (en) 2010-11-17

Family

ID=43073292

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2009100840910A Pending CN101887361A (en) 2009-05-14 2009-05-14 Method for efficiently processing delayed tasks under multi-thread environment

Country Status (1)

Country Link
CN (1) CN101887361A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105068861A (en) * 2015-07-09 2015-11-18 合肥君正科技有限公司 Transaction execution method and device
CN109766131A (en) * 2017-11-06 2019-05-17 上海宝信软件股份有限公司 The system and method for the intelligent automatic upgrading of software is realized based on multithreading

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105068861A (en) * 2015-07-09 2015-11-18 合肥君正科技有限公司 Transaction execution method and device
CN109766131A (en) * 2017-11-06 2019-05-17 上海宝信软件股份有限公司 The system and method for the intelligent automatic upgrading of software is realized based on multithreading
CN109766131B (en) * 2017-11-06 2022-04-01 上海宝信软件股份有限公司 System and method for realizing intelligent automatic software upgrading based on multithreading technology

Similar Documents

Publication Publication Date Title
US9880875B2 (en) Apparatus and method for hardware-based task scheduling
CN105389209A (en) Asynchronous batch task processing method and system
US9104500B1 (en) Lock-free job scheduler for multi-processor systems
CN106155806B (en) Multitask scheduling method and server
CN102455933A (en) Method for increasing multi-tasking efficiency through thread management
CN102902582A (en) Managing processes within suspend states and execution states
WO2009023461A1 (en) Multi-threaded processing with reduced context switching
CN109660569B (en) Multitask concurrent execution method, storage medium, device and system
CN107479981B (en) Processing method and device for realizing synchronous call based on asynchronous call
CN102999387A (en) Process running device and method
CN102455934A (en) Workflow scheduling method and device
CN108958915A (en) Timed task executes method and device
CN101887361A (en) Method for efficiently processing delayed tasks under multi-thread environment
CN103034480B (en) A kind of embedded system timer implementation method
CN106484502B (en) Task scheduling method, device and system
WO2002071218A2 (en) Method of and system for withdrawing budget from a blocking task
WO2018206793A1 (en) Multicore processing system
CN106406997B (en) Timer scheduling method and device
CN108255591B (en) Unified exception handling method for partition operating system
US9753785B2 (en) Asynchronous dispatcher for application framework
CN101349975B (en) Method for implementing interrupt bottom semi-section mechanism in embedded operation system
WO2008157455A2 (en) Notifying user mode scheduler of blocking events
CN112987904A (en) Heartbeat control method and device
JP2011018281A (en) System, method and program for managing job execution
CN111026526B (en) Timer configuration method and device for program, storage medium and terminal equipment

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
ASS Succession or assignment of patent right

Owner name: CHINA GAMES COMPETITIVE CULTURE CO., LTD.

Free format text: FORMER OWNER: GRIZZLY (BEIJING) TECHNOLOGY CO., LTD.

Effective date: 20111111

C41 Transfer of patent application or patent right or utility model
COR Change of bibliographic data

Free format text: CORRECT: ADDRESS; FROM: 102218 CHANGPING, BEIJING TO: 570215 HAIKOU, HAINAN PROVINCE

TA01 Transfer of patent application right

Effective date of registration: 20111111

Address after: 570215 room 17A, crystal building, Pearl River Plaza, No. 2, Kun Kun Road, Hainan, Haikou

Applicant after: Middle reaches competitive culture Limited by Share Ltd

Address before: 102218, 701, building 39, 2 District, Tiantongyuan north, Beijing, Changping District, 7

Applicant before: Huixiong (Beijing) Technology Co., Ltd.

C02 Deemed withdrawal of patent application after publication (patent law 2001)
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20101117