CN112925626B - Timer task processing method and device and server - Google Patents

Timer task processing method and device and server Download PDF

Info

Publication number
CN112925626B
CN112925626B CN202110300983.0A CN202110300983A CN112925626B CN 112925626 B CN112925626 B CN 112925626B CN 202110300983 A CN202110300983 A CN 202110300983A CN 112925626 B CN112925626 B CN 112925626B
Authority
CN
China
Prior art keywords
task
timer
timer task
scheduler
lock
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110300983.0A
Other languages
Chinese (zh)
Other versions
CN112925626A (en
Inventor
王小威
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Embedway Technologies Shanghai Corp
Original Assignee
Embedway Technologies Shanghai Corp
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 Embedway Technologies Shanghai Corp filed Critical Embedway Technologies Shanghai Corp
Priority to CN202110300983.0A priority Critical patent/CN112925626B/en
Publication of CN112925626A publication Critical patent/CN112925626A/en
Application granted granted Critical
Publication of CN112925626B publication Critical patent/CN112925626B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4812Task transfer initiation or dispatching by interrupt, e.g. masked
    • G06F9/4825Interrupt from clock, e.g. time of day
    • 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/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • G06F9/526Mutual exclusion algorithms
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Power Sources (AREA)

Abstract

The invention provides a timer task processing method, a device and a server, which are applied to the technical field of computers. Compared with the prior art, the method can effectively avoid the execution frequency without difference, thereby avoiding the waste of processor resources and being beneficial to improving the execution efficiency of the real-time processing system.

Description

Timer task processing method and device and server
Technical Field
The invention belongs to the technical field of computers, and particularly relates to a timer task processing method, a timer task processing device and a server.
Background
In practical application, application software in a real-time processing system often sets a large number of timer tasks to be executed according to a certain period, such as scanning hash tables, and performs timeout scanning on each hash table according to a certain scanning period, so that the effectiveness of the hash table is ensured and the real-time requirement of the real-time processing system is met.
Different hash tables have different requirements on real-time performance, some software business information is updated quickly, the hash tables are required to be invalid after being overtime quickly, and the overtime scanning frequency is high; some software service information is updated slowly, and correspondingly, the overtime time of the hash table is longer, and the overtime scanning frequency is lower. The timer tasks in a real-time processing system mostly have similar characteristics as the scan hash table, i.e. have different processing frequency requirements.
In the prior art, the execution frequency of timer tasks is realized based on a hardware timer, namely, all timer tasks are processed according to a fixed frequency, taking a scanning hash table as an example, for a hash table with long timeout time, the frequency of performing timeout scanning on the hash table is far greater than the actual requirement, and a large proportion of scanning processes are unnecessary, so that the timer task processing method in the prior art inevitably causes waste of processor resources and even affects the execution efficiency of the whole real-time processing system.
Disclosure of Invention
Accordingly, the present invention is directed to a method, an apparatus, and a server for processing timer tasks, which set a corresponding sleep time threshold for each timer task, implement differentiated processing of each timer task based on the sleep time threshold, and avoid non-differentiated execution frequency, thereby avoiding waste of processor resources, and being helpful for improving execution efficiency of a real-time processing system, and specifically comprises the following steps:
in a first aspect, the present invention provides a method for processing a timer task, including:
acquiring a lock of a task scheduler to lock the task scheduler;
the task scheduler comprises a preset circular linked list, wherein the preset circular linked list records a plurality of pieces of task information, and any piece of task information comprises a state of a timer task, a sleep time length threshold value of the timer task and the timer task;
determining a current timer task to be processed in each timer task based on the preset circular linked list;
if the current to-be-processed timer task is not in the running state and the dormancy time length of the current to-be-processed timer task is greater than or equal to the corresponding dormancy time length threshold, determining the current to-be-processed timer task as an executable task, and marking the executable task as the running state;
releasing the lock of the task scheduler;
and executing the executable task.
Optionally, after the executable task is executed, the method further includes:
acquiring a lock of the task scheduler;
marking the executable task as an idle state and releasing the lock of the task scheduler.
Optionally, the determining, based on the preset circular linked list, the current timer task to be processed in each timer task includes:
determining a timer task serving as an executable task in the previous cycle;
traversing the preset circular linked list, and taking the next timer task serving as the timer task of the executable task in the previous period in the preset circular linked list as the current timer task to be processed.
Optionally, the task scheduler further includes a to-be-deleted timer task list, and before the releasing the lock of the task scheduler, further includes:
acquiring a timer task to be deleted in the timer task list to be deleted;
and releasing the timer task to be deleted after releasing the lock of the task scheduler.
Optionally, the timer task processing method provided in the first aspect of the present invention further includes:
task information of a timer task is obtained, wherein the task information comprises the timer task, a timer scanning function, a timer overtime processing function and overtime time;
calculating a sleep time length threshold corresponding to the timer task according to the timeout time;
acquiring a lock of the task scheduler;
adding task information of the timer task and a sleep time length threshold corresponding to the timer task into the preset circular linked list;
releasing the lock of the task scheduler.
Optionally, the calculating the sleep duration threshold corresponding to the timer task according to the timeout time includes:
calling a preset mapping relation, wherein the corresponding relation between the timeout time range and the dormancy time threshold is recorded in the preset mapping relation;
determining a timeout time range to which the timeout time of the timer task belongs, and obtaining a target timeout time range;
and taking the sleep time length threshold corresponding to the target timeout time range in the preset mapping relation as the sleep time length threshold corresponding to the timer task.
Optionally, the timer task processing method provided in the first aspect of the present invention further includes:
responding to a task deleting request, and acquiring a lock of the task scheduler;
determining a timer task to be deleted corresponding to the task deletion request according to the preset circular linked list;
if the timer task to be deleted is in an operating state, deleting task information corresponding to the timer task to be deleted from the preset circular linked list, and storing the task information of the timer task to be deleted in the timer task list to be deleted;
if the timer task to be deleted is not in the running state, releasing the timer task to be deleted;
releasing the lock of the task scheduler.
Optionally, the timer task processing method provided in the first aspect of the present invention further includes:
responding to the time modification request, and acquiring a lock of the task scheduler;
the time modification request comprises a timer task to be modified and a modified timeout time;
if the timer task to be modified is not in the running state, updating the timeout time of the timer task to be modified in the preset circular linked list to the modified timeout time, and updating a sleep duration threshold corresponding to the modified timeout time;
releasing the lock of the task scheduler.
In a second aspect, the present invention provides a timer task processing device, including:
an acquisition unit configured to acquire a lock of a task scheduler to lock the task scheduler;
the task scheduler comprises a preset circular linked list, wherein the preset circular linked list records a plurality of pieces of task information, and any piece of task information comprises a state of a timer task, a sleep time length threshold value of the timer task and the timer task;
the first determining unit is used for determining a current timer task to be processed in each timer task based on the preset circular linked list;
the second determining unit is used for determining the current to-be-processed timer task as an executable task and marking the executable task as an running state if the current to-be-processed timer task is not in the running state and the dormancy time of the current to-be-processed timer task is greater than or equal to a corresponding dormancy time threshold;
a releasing unit for releasing the lock of the task scheduler;
and the execution unit is used for executing the executable task.
In a third aspect, the present invention provides a server comprising: a memory and a processor; the memory stores a program adapted to be executed by the processor to implement the timer task processing method according to any one of the first aspects of the present invention.
The task scheduler provided by the timer task processing method comprises a preset circular linked list, wherein a plurality of pieces of task information are recorded in the preset circular linked list, any piece of task information comprises a state of a timer task, a sleep time length threshold value of the timer task and the timer task, after the task scheduler is locked, a current timer task to be processed is firstly determined in each timer task based on the preset circular linked list, judgment is carried out based on the task information of the current timer task to be processed recorded in the preset circular linked list, if the current timer task to be processed is not in a running state and the sleep time length of the current timer task to be processed is greater than or equal to the corresponding sleep time length threshold value, the current timer task to be processed is determined to be an executable task, the executable task is marked as the running state, the executable task is guaranteed not to be repeatedly processed, and the executable task is executed after the lock of the task scheduler is released.
According to the timer task processing method provided by the invention, the sleep time length threshold values of different timer tasks are recorded through the preset circular linked list, so that each timer task corresponds to the self-matched scanning frequency, and whether the current timer task to be processed needs to be executed or not can be judged through the size relation between the sleep time length of the current timer task to be processed and the corresponding sleep time length threshold value and the state of the timer task, therefore, a technician can realize differential overtime scanning on different timer tasks only by setting the sleep time length threshold value of the timer task according to actual scanning requirements, and compared with the prior art, the non-differential execution frequency can be effectively avoided, so that the waste of processor resources is avoided, and the execution efficiency of a real-time processing system is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flowchart of a method for processing timer tasks according to an embodiment of the present invention;
FIG. 2 is a flowchart of another method for processing timer tasks according to an embodiment of the present invention;
FIG. 3 is a flowchart of a further method for processing timer tasks according to an embodiment of the present invention;
FIG. 4 is a flowchart of a further timer task processing method provided by an embodiment of the present invention;
FIG. 5 is a block diagram of a timer task processing device according to an embodiment of the present invention;
fig. 6 is a block diagram of a server according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Referring to fig. 1, a flowchart of a timer task processing method provided by an embodiment of the present invention may be applied to an electronic device, which may be an electronic device with data processing capability, such as a notebook computer, a PC (personal computer), a tablet computer, etc., and specifically, is applied to at least one thread in a processor set in the electronic device, and obviously, the electronic device may also be implemented by a server on a network side in some cases; referring to fig. 1, a flowchart of a method for processing a timer task according to an embodiment of the present invention may include:
s100, acquiring a lock of the task scheduler to lock the task scheduler.
The task scheduler provided by the embodiment of the invention comprises a preset circular linked list, wherein the preset circular linked list is used for recording task information of a timer task, and the preset circular list comprises a plurality of pieces of task information in most cases.
Specifically, for any piece of task information, an identification for distinguishing and identifying a timer task, a state of the timer task, a sleep duration threshold of the timer task, a timer trigger function, a timer timeout processing function, and the like are recorded therein. Of course, in practical application, the task information may also include other information related to the timer task, which is not listed here.
The states of the timer task in this embodiment mainly include an operation transition state, an idle state and a sleep state according to related rules of the task executed by the processor thread in the prior art. It should be noted that, in particular, a task is in a running state, which means that there are threads in the processor that are executing the task, in which case other threads are not able to execute the task.
The lock of the task scheduler can be a set of functions when the lock is realized, the processing of the task scheduler can be legal and reliable through the lock, after any thread acquires the lock of the task scheduler, the unique processing authority for the task scheduler is acquired, other threads cannot acquire the task scheduler, and the consistency of multi-thread operation can be ensured through locking the task scheduler, namely, the operation of the multi-thread on the same timer task can not be interfered with each other. Acquiring a lock to the task scheduler means that the task scheduler can be locked.
As regards the specific implementation of the lock and the locking task scheduler, reference may be made to the prior art implementation, which is not limited by the present invention.
Optionally, in practical application, the task scheduler may include two states of running and stopping, so before executing S110, the state of the task scheduler may also be determined, if the task scheduler is in a running state, S110 is continuously executed, and conversely, if the task scheduler is in a stopping state, the current executing process is exited.
S110, determining a current to-be-processed timer task in the timer tasks based on a preset circular linked list.
Optionally, as described above, a plurality of task information is recorded in the preset circular linked list, after the task scheduler is locked, a timer task serving as an executable task in the previous period is first determined, then the preset circular linked list is traversed, and a next timer task serving as the executable task in the previous period in the preset circular linked list is used as a current timer task to be processed.
S120, judging whether the current timer task to be processed is in an operation state, if so, returning to execute S110, and if not, executing S130.
As described above, the thread or the processor does not have the right to process the task in the running state, so this step needs to determine whether the obtained current to-be-processed timer task is in the running state, if so, it is determined that the timer task cannot be processed, and then S110 is executed back, and based on the preset loop list, the current to-be-processed timer task is determined in each timer task, and loops back and forth until the obtained current to-be-processed thread is not in the running state, and S130 is executed continuously.
S130, judging whether the sleep time length of the current to-be-processed timer task is greater than or equal to a corresponding sleep time length threshold, if so, executing S140, and if not, executing S110.
Taking hash table scanning as an example, in practical application, different hash tables have different real-time requirements, and when the same hash table is applied to different services, the same hash table can also correspond to different real-time requirements due to the difference between the services, namely, the hash tables correspond to different timeout periods.
Based on the above, the timer task processing method provided by the embodiment of the invention sets different sleep time thresholds for each timer task according to different timeout time. If the sleep time length of the current to-be-processed timer task is greater than or equal to the sleep time length threshold corresponding to the current to-be-processed timer task, S140 is executed, and conversely, if the sleep time length of the current to-be-processed timer task is less than the corresponding sleep time length threshold, S150 is executed.
It should be noted that, the calculation of the sleep duration of the timer task may be implemented based on the prior art, and is not expanded here.
In the method provided by the embodiment of the invention, different timer tasks can be registered for the same hash table, so that the same hash table corresponds to different sleep time thresholds when being applied to different services, and the specific registration process is developed in the subsequent content and is not described in detail herein.
S140, determining the current to-be-processed timer task as an executable task, and marking the executable task as an operating state.
And under the condition that the current timer task to be processed is not in an operating state and the dormancy time length is greater than or equal to the corresponding dormancy time length threshold value, determining the current timer task to be processed as an executable task, and acquiring the executable task.
To ensure that other threads do not process the executable task at the same time, ensuring the validity and uniqueness of this process, the state of the executable task needs to be marked as running at the same time.
S150, releasing the lock of the task scheduler.
After the executable task is acquired, the lock of the task scheduler may be released. It is conceivable that after releasing the lock of the task scheduler, other threads may lock the task scheduler and execute the timer task processing method provided by the embodiments of the present invention, so in this method, only one thread may acquire the task scheduler at the same time, and acquire a timer task from the task scheduler; at the same time, there may be multiple threads handling different timer tasks, i.e., each thread has its own timer task.
S160, executing the executable task.
Optionally, the task information of the preset circulation list records a timer trigger function and a timer timeout processing function corresponding to each timer task, and the specific implementation process of executing the executable task is implemented based on the functions, and the specific implementation process can be implemented based on the prior art and is not expanded here.
According to the timer task processing method provided by the invention, the sleep time length threshold values of different timer tasks are recorded through the preset circular linked list, so that each timer task corresponds to the self-matched scanning frequency, and whether the current timer task to be processed needs to be executed or not can be judged through the size relation between the sleep time length of the current timer task to be processed and the corresponding sleep time length threshold value and the state of the timer task, therefore, a technician can realize differential overtime scanning on different timer tasks only by setting the sleep time length threshold value of the timer task according to actual scanning requirements, and compared with the prior art, the non-differential execution frequency can be effectively avoided, so that the waste of processor resources is avoided, and the execution efficiency of a real-time processing system is improved.
Furthermore, by applying the lock of the task scheduler and the state of the timer task, a plurality of threads can process a plurality of executable timer tasks simultaneously by applying the timer task processing method provided by the embodiment of the invention, thereby realizing multithreading scheduling and effectively improving the realization efficiency of overtime scanning.
Meanwhile, the timer task processing method is decoupled from the service module of the application software, so that the timer task processing method can be applied to various overtime scanning scenes and has higher flexibility.
Optionally, after the timer task corresponding to the executable task is scanned, the lock of the task scheduler needs to be acquired again, the executable task processed in the previous step is further marked as an idle state, and the lock of the task scheduler is released, so that other threads can continue to process the timer task according to requirements.
Optionally, a to-be-deleted timer task list is further set in the task scheduler provided in the embodiment of the present invention, where a to-be-deleted timer task is recorded in the to-be-deleted timer task list, and in the timer task processing method provided in the embodiment shown in fig. 1, before releasing the lock of the task scheduler, the to-be-deleted timer task in the to-be-deleted timer task list may be obtained synchronously, and after releasing the lock of the task scheduler, the to-be-deleted timer task may be released. Based on the operation, the task scheduler is locked once, and two operations can be executed simultaneously, so that the execution efficiency is further improved, and the resources of the processor are fully applied.
The adding process of each timer task to be deleted in the timer task list to be deleted can be described with reference to the embodiment shown in fig. 2. Optionally, referring to fig. 2, on the basis of the embodiment shown in fig. 1, the flow of the timer task processing method provided in this embodiment may include:
s200, responding to the task deleting request, and acquiring the lock of the task scheduler.
The task deletion operation of the timer is usually triggered by a task deletion request, and in response to the task deletion request, the method for processing a task of the timer according to the present embodiment first obtains the lock of the task scheduler, and specific content may refer to the foregoing content, which is not described herein, and for the sending of the task deletion request, the method may refer to the prior art, which is not described herein.
Optionally, since a plurality of timer tasks are recorded in the preset circular linked list, in order to facilitate determining a specific timer task to be deleted, the task deletion request should include identification information capable of uniquely determining the timer task to be deleted, for example, a name, an ID number, and the like of the timer task to be deleted.
S210, determining a timer task to be deleted corresponding to the task deletion request according to a preset circular linked list.
As described above, the task deletion request includes the identification information of the timer task to be deleted, and the task to be deleted corresponding to the task deletion request can be determined by querying the preset circular linked list according to the identification information of the timer task to be deleted included in the task deletion request.
S220, judging whether the timer task to be deleted is in an operation state, if not, executing S230, and if so, executing S250.
After determining the timer task to be deleted, it is further determined whether the timer task to be deleted is in an operating state, as described above, and the other threads are not authorized to make further processing on the task in the operating state, so if the timer task to be deleted is in the operating state, S250 is executed, and if not, S230 is executed.
S230, releasing the timer task to be deleted.
If the timer task to be deleted is not in the running state, the timer task to be deleted is directly released, and the deleting operation is completed.
S240, releasing the lock of the task scheduler.
After deleting the timer task to be deleted, the lock of the task scheduler can be released, so that other threads can continue to process.
S250, deleting task information corresponding to the timer task to be deleted from a preset circular linked list, and storing the task information of the timer task to be deleted in a timer task list to be deleted.
If the timer task to be deleted is in an operation state and cannot be deleted directly, firstly removing task information corresponding to the timer task to be deleted from a preset circulation list, then storing the task information of the timer task to be deleted in the timer task list to be deleted, and performing release processing on the timer task to be deleted when the method provided by the embodiment of fig. 1 is executed subsequently.
Optionally, referring to fig. 3 on the basis of the embodiment shown in fig. 1, fig. 3 is a flowchart of another method for processing a timer task according to an embodiment of the present invention, where the embodiment provides a method for adding a timer task in a preset circular linked list, and the specific flow includes:
s300, task information of a timer task is obtained.
Specifically, the task information includes an identification of a timer task, a timer scan function, a timer timeout processing function, and a timeout time. In practical applications, the task information may also include other information related to the timer task, which is not listed here.
S310, calculating a sleep time threshold corresponding to the timer task according to the timeout time.
Optionally, the embodiment of the present invention provides a preset mapping relationship, where a correspondence relationship between a timeout period range and a sleep duration threshold is recorded in the preset mapping relationship, for example, the timeout period is less than 5 minutes, and the sleep duration threshold is zero; a sleep duration threshold of 1 millisecond with a timeout time of 5 minutes to 30 minutes; the sleep duration threshold for timeout times greater than 30 minutes is 1s. The dormancy time threshold value is not more than 1s, so that the timeliness of the timeout is controlled within 1s.
After the preset mapping relation is called, firstly determining the overtime time range of the overtime time of the timer task to obtain a target overtime time range, and then taking the sleep time threshold corresponding to the target overtime time range in the preset mapping relation as the sleep time threshold corresponding to the timer task.
S320, acquiring a lock of the task scheduler.
The execution of this step is referred to in the foregoing and will not be repeated here.
S330, adding task information of the timer task and a sleep time length threshold corresponding to the timer task into a preset circular linked list.
After the sleep time length threshold of the timer task is determined, the task information of the timer task and the corresponding sleep time length threshold can be added into a preset circular linked list.
S240, releasing the lock of the task scheduler.
The execution of this step is referred to in the foregoing and will not be repeated here.
By the method provided by the embodiment, different timer tasks can be registered for one hash table, and of course, the timeout time of each timer task is determined based on the software service of a specific application, and meanwhile, the scanning frequency of the same hash table in different application scenes can be adjusted by setting different sleep time thresholds, so that the timer processing requirements of multiple software services are met.
In practical application, the time-out time of each timer task is inevitably adjusted, therefore, the invention also provides a timer task processing method, and on the basis of any embodiment, the time-out time is modified.
Optionally, referring to fig. 4, the method for processing a timer task provided in this embodiment further includes, based on the method provided in any one of the foregoing embodiments:
s400, responding to the time modification request, and acquiring the lock of the task scheduler.
Similar to registering and deleting the timer task, the modification of the timeout is triggered based on a request, and in this embodiment, the time modification request includes at least a to-be-modified timer task and a modified timeout, where the to-be-modified timer task may be uniquely characterized by an identifier of the timer task, such as a name or ID number.
S410, judging whether the timer task to be modified is in an operating state, and if not, executing S420.
As described above, S420 is executed only if the timer task to be modified is not in the running state, and the current execution process is exited if the timer task to be modified is in the running state.
S420, updating the timeout time of the timer task to be modified in the preset circular linked list to be modified timeout time, and updating the sleep time threshold corresponding to the modified timeout time.
It should be noted that, for the determination of the sleep duration threshold corresponding to the modified timeout period, the implementation process of S310 in the embodiment shown in fig. 3 may be referred to, which is not described herein.
S430, releasing the lock of the task scheduler.
The execution of this step is referred to in the foregoing and will not be repeated here.
The following describes a timer task processing device provided by the embodiment of the present invention, where the timer task processing device described below may be regarded as a functional module architecture to be set in a central device in order to implement the timer task processing method provided by the embodiment of the present invention; the following description may be referred to with respect to the above.
Optionally, referring to fig. 5, fig. 5 is a block diagram of a timer task processing device according to an embodiment of the present invention, where the timer task processing device includes:
an acquisition unit 10 for acquiring a lock of a task scheduler to lock the task scheduler;
the task scheduler comprises a preset circular linked list, wherein the preset circular linked list records a plurality of pieces of task information, and any piece of task information comprises a state of a timer task, a sleep time length threshold value of the timer task and the timer task;
a first determining unit 20, configured to determine, based on the preset circular linked list, a current timer task to be processed among the timer tasks;
a second determining unit 30, configured to determine the current to-be-processed timer task as an executable task and mark the executable task as an running state if the current to-be-processed timer task is not in the running state and the sleep time length of the current to-be-processed timer task is greater than or equal to the corresponding sleep time length threshold;
a releasing unit 40 for releasing the lock of the task scheduler;
and an execution unit 50 for executing the executable task.
Optionally, referring to fig. 6, fig. 6 is a block diagram of a server according to an embodiment of the present invention, and referring to fig. 4, the method may include: at least one processor 100, at least one communication interface 200, at least one memory 300, and at least one communication bus 400;
in the embodiment of the present invention, the number of the processor 100, the communication interface 200, the memory 300 and the communication bus 400 is at least one, and the processor 100, the communication interface 200 and the memory 300 complete the communication with each other through the communication bus 400; it will be apparent that the communication connection schematic shown in the processor 100, the communication interface 200, the memory 300 and the communication bus 400 shown in fig. 6 is only optional;
optionally, the communication interface 200 may be an interface of a communication module, such as an interface adapted to a vehicle-mounted OBD interface or other CAN network interface;
the processor 100 may be a central processing unit CPU, or a specific integrated circuit ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement embodiments of the present invention.
The memory 300, which stores application programs, may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
The processor 100 is specifically configured to execute an application program in the memory, so as to implement any embodiment of the timer task processing method described above.
In the present specification, each embodiment is described in a progressive manner, and each embodiment is mainly described in a different point from other embodiments, and identical and similar parts between the embodiments are all enough to refer to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative elements and steps are described above generally in terms of functionality in order to clearly illustrate the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. The software modules may be disposed in Random Access Memory (RAM), memory, read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (8)

1. A timer task processing method, comprising:
acquiring a lock of a task scheduler to lock the task scheduler;
the task scheduler comprises a preset circular linked list, wherein the preset circular linked list records a plurality of pieces of task information, and any piece of task information comprises a state of a timer task, a sleep time length threshold value of the timer task and the timer task; the sleep duration threshold is calculated according to the timeout time of the timer task;
determining a current timer task to be processed in each timer task based on the preset circular linked list;
if the current to-be-processed timer task is not in the running state and the dormancy time length of the current to-be-processed timer task is greater than or equal to the corresponding dormancy time length threshold, determining the current to-be-processed timer task as an executable task, and marking the executable task as the running state;
releasing the lock of the task scheduler;
executing the executable task;
the determining, based on the preset circular linked list, a current timer task to be processed in the timer tasks includes:
determining a timer task serving as an executable task in the previous cycle;
traversing the preset circular linked list, and taking the next timer task serving as the timer task of the executable task in the previous period in the preset circular linked list as the current timer task to be processed;
the method for calculating the sleep duration threshold corresponding to the timer task according to the timeout time comprises the following steps: calling a preset mapping relation, wherein the corresponding relation between the timeout time range and the dormancy time threshold is recorded in the preset mapping relation; determining a timeout time range to which the timeout time of the timer task belongs, and obtaining a target timeout time range; and taking the sleep time length threshold corresponding to the target timeout time range in the preset mapping relation as the sleep time length threshold corresponding to the timer task.
2. The timer task processing method according to claim 1, further comprising, after completion of execution of the executable task:
acquiring a lock of the task scheduler;
marking the executable task as an idle state and releasing the lock of the task scheduler.
3. The timer task processing method according to claim 1, wherein the task scheduler further includes a timer task list to be deleted, and before the releasing the lock of the task scheduler, further includes:
acquiring a timer task to be deleted in the timer task list to be deleted;
and releasing the timer task to be deleted after releasing the lock of the task scheduler.
4. The timer task processing method according to claim 1, characterized by further comprising:
task information of a timer task is obtained, wherein the task information comprises the timer task, a timer scanning function, a timer overtime processing function and overtime time;
calculating a sleep time length threshold corresponding to the timer task according to the timeout time;
acquiring a lock of the task scheduler;
adding task information of the timer task and a sleep time length threshold corresponding to the timer task into the preset circular linked list;
releasing the lock of the task scheduler.
5. A timer task processing method as claimed in claim 3, further comprising:
responding to a task deleting request, and acquiring a lock of the task scheduler;
determining a timer task to be deleted corresponding to the task deletion request according to the preset circular linked list;
if the timer task to be deleted is in an operating state, deleting task information corresponding to the timer task to be deleted from the preset circular linked list, and storing the task information of the timer task to be deleted in the timer task list to be deleted;
if the timer task to be deleted is not in the running state, releasing the timer task to be deleted;
releasing the lock of the task scheduler.
6. The timer task processing method according to claim 1, characterized by further comprising:
responding to the time modification request, and acquiring a lock of the task scheduler;
the time modification request comprises a timer task to be modified and a modified timeout time;
if the timer task to be modified is not in the running state, updating the timeout time of the timer task to be modified in the preset circular linked list to the modified timeout time, and updating a sleep duration threshold corresponding to the modified timeout time;
releasing the lock of the task scheduler.
7. A timer task processing device, comprising:
an acquisition unit configured to acquire a lock of a task scheduler to lock the task scheduler;
the task scheduler comprises a preset circular linked list, wherein the preset circular linked list records a plurality of pieces of task information, and any piece of task information comprises a state of a timer task, a sleep time length threshold value of the timer task and the timer task; the sleep duration threshold is calculated according to the timeout time of the timer task;
the first determining unit is used for determining a current timer task to be processed in each timer task based on the preset circular linked list; the determining, based on the preset circular linked list, a current timer task to be processed in the timer tasks includes: determining a timer task serving as an executable task in the previous cycle; traversing the preset circular linked list, and taking the next timer task serving as the timer task of the executable task in the previous period in the preset circular linked list as the current timer task to be processed;
the second determining unit is used for determining the current to-be-processed timer task as an executable task and marking the executable task as an running state if the current to-be-processed timer task is not in the running state and the dormancy time of the current to-be-processed timer task is greater than or equal to a corresponding dormancy time threshold;
a releasing unit for releasing the lock of the task scheduler;
an execution unit configured to execute the executable task;
the method for calculating the sleep duration threshold corresponding to the timer task according to the timeout time comprises the following steps: calling a preset mapping relation, wherein the corresponding relation between the timeout time range and the dormancy time threshold is recorded in the preset mapping relation; determining a timeout time range to which the timeout time of the timer task belongs, and obtaining a target timeout time range; and taking the sleep time length threshold corresponding to the target timeout time range in the preset mapping relation as the sleep time length threshold corresponding to the timer task.
8. A server, comprising: a memory and a processor; the memory stores a program adapted to be executed by the processor to implement the timer task processing method according to any one of claims 1 to 6.
CN202110300983.0A 2021-03-22 2021-03-22 Timer task processing method and device and server Active CN112925626B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110300983.0A CN112925626B (en) 2021-03-22 2021-03-22 Timer task processing method and device and server

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110300983.0A CN112925626B (en) 2021-03-22 2021-03-22 Timer task processing method and device and server

Publications (2)

Publication Number Publication Date
CN112925626A CN112925626A (en) 2021-06-08
CN112925626B true CN112925626B (en) 2023-04-25

Family

ID=76175290

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110300983.0A Active CN112925626B (en) 2021-03-22 2021-03-22 Timer task processing method and device and server

Country Status (1)

Country Link
CN (1) CN112925626B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109815007A (en) * 2018-12-15 2019-05-28 平安科技(深圳)有限公司 Thread control method, device, electronic equipment and storage medium based on cloud monitoring
CN110275766A (en) * 2019-06-25 2019-09-24 深圳前海微众银行股份有限公司 A kind of task processing method and device

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103345415B (en) * 2013-07-30 2016-06-22 广东欧珀移动通信有限公司 The terminal power-economizing method of management intervalometer and device
CN104951361B (en) * 2014-03-27 2018-10-09 阿里巴巴集团控股有限公司 A kind of triggering method and device of timed task
US10127061B2 (en) * 2015-08-21 2018-11-13 International Business Machines Corporation Controlling priority of dynamic compilation
CN110968405A (en) * 2018-09-30 2020-04-07 杭州海康威视系统技术有限公司 Method and device for detecting planned tasks
CN111465087B (en) * 2020-03-31 2023-07-18 上海庆科信息技术有限公司 Task scheduling processing method, device, storage medium, processor and system

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109815007A (en) * 2018-12-15 2019-05-28 平安科技(深圳)有限公司 Thread control method, device, electronic equipment and storage medium based on cloud monitoring
CN110275766A (en) * 2019-06-25 2019-09-24 深圳前海微众银行股份有限公司 A kind of task processing method and device

Also Published As

Publication number Publication date
CN112925626A (en) 2021-06-08

Similar Documents

Publication Publication Date Title
US20040002974A1 (en) Thread based lock manager
CN109766349B (en) Task duplicate prevention method, device, computer equipment and storage medium
JP2004527857A5 (en)
CN112099962B (en) Distributed lock implementation method and device and electronic equipment
CN110263048B (en) Method and device for processing large-batch data, computer equipment and storage medium
CN112783760B (en) Processing method and device for test cases and storage medium
CN109842621A (en) A kind of method and terminal reducing token storage quantity
CN111858086B (en) Processing method and storage medium for queue timeout in request task processing
CN112860387A (en) Distributed task scheduling method and device, computer equipment and storage medium
US8108573B2 (en) Apparatus, system, and method for enqueue prioritization
CN112925626B (en) Timer task processing method and device and server
CN110908968B (en) Method, device, equipment and storage medium for avoiding frightened groups during file lock unlocking
CN108776633B (en) Method for monitoring process operation, terminal equipment and computer readable storage medium
CN116055664B (en) Method, device and storage medium for sharing memory for video processing process
CN111597056A (en) Distributed scheduling method, system, storage medium and device
WO2022267676A1 (en) Data processing method and apparatus for shared memory, and device and medium
CN114035970B (en) Data concurrent competition conflict detection analysis method and system
CN113254167B (en) Distributed transaction processing method, device and system and electronic equipment
US7660888B2 (en) Indicating network resource availability methods, system and program product
CN117806897A (en) Container group abnormality detection method and device, storage medium and electronic equipment
WO2019237539A1 (en) Method for processing monitoring data, server, and computer-readable storage medium
CN114398238A (en) Application system interface monitoring method and device, computer equipment and storage medium
CN115934540A (en) Test account management method and device, computing equipment and storage medium
CN116662267B (en) Distributed application snapshot system based on cloud protogenesis and snapshot creation method
CN116257328A (en) Data distribution method, device, electronic equipment and computer readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant