Timing method and device, equipment and medium
By creating a timing thread in the application to manage multiple timing tasks, the system performance degradation caused by excessive creation of timing threads in the prior art is solved, and the reuse of timing threads and resource savings are achieved, and the system performance is improved.
Patent Information
- Application Number
- CN202310530446.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-11
- Publication Date
- 2024-11-12
AI Technical Summary
When existing applications with timing functions use the delay operation tool provided by JAVA to implement timing functions, they will cause the continuous creation of timing threads and occupy system resources, resulting in system performance degradation.
Provides a timing method by creating a timing thread when the application starts, for timing multiple timing tasks, and creating corresponding task threads when the timing task reaches the trigger time, executing a callback method, and after the timing task is completed Delete task threads to achieve reuse of timed threads and save resources.
The management of multiple timing tasks is achieved through one timing thread, which avoids excessive creation and occupation of timing threads, improves system performance, and saves system resources.
Smart Images

Figure CN118939388A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a timing method, device, equipment and medium. Background Art
[0002] At present, with the widespread use of applications in electronic devices, applications with timing functions such as alarm reminders, daily affairs reminders, etc. are also very popular. In the existing timing execution logic design scheme of applications with timing functions, JAVA's built-in delay operation tools, such as ScheduledThreadPoolExecutor, are used to implement the timing function of the application through JAVA's built-in delay operation tools.
[0003] However, in the existing timing execution logic design scheme of the application program that includes the timing function, when the delay operation tool provided by JAVA is used to implement the timing function of the application program, each time the application program starts a timing task, a new timing thread corresponding to the timing task will be started to perform timing, and after the timing task is completed, the timing thread corresponding to the timing task will also continue to exist. As the number of timing tasks increases, the number of timing threads in the system will also increase accordingly, and thus there is a problem that the timing threads always occupy system resources, resulting in a decrease in system performance. Summary of the invention
[0004] In order to solve the above technical problems, the present disclosure provides a timing method, device, equipment and medium.
[0005] A first aspect of an embodiment of the present disclosure provides a timing method, the method comprising:
[0006] In response to the application being started, a timing thread is created, where the timing thread is used to time multiple timing tasks in the application;
[0007] Obtain at least one timing task, wherein the at least one timing task includes a trigger time and a callback method, and the callback method is a function interface of a preset operation triggered at the trigger time;
[0008] For each timing task, call the timing thread to time the timing task, and in response to the timing reaching the trigger time corresponding to the timing task, create a task thread corresponding to the timing task;
[0009] The callback method corresponding to the timing task is executed based on the task thread;
[0010] After detecting that the timing task has been executed, the task thread corresponding to the timing task is deleted.
[0011] A second aspect of an embodiment of the present disclosure provides a timing device, the device comprising:
[0012] A first creation module is used to create a timing thread in response to the application being started, where the timing thread is used to time multiple timing tasks in the application;
[0013] A task acquisition module, used to acquire at least one timing task, wherein the at least one timing task includes a trigger time and a callback method, and the callback method is a function interface of a preset operation triggered at the trigger time;
[0014] A second creation module is used to call a timing thread for each timing task to time the timing task, and create a task thread corresponding to the timing task in response to the timing reaching a trigger time corresponding to the timing task;
[0015] The task execution module is used to execute the callback method corresponding to the timing task based on the task thread;
[0016] The thread deletion module is used to delete the task thread corresponding to the timing task after detecting that the timing task has been executed.
[0017] A third aspect of an embodiment of the present disclosure provides an electronic device, the device comprising:
[0018] Memory;
[0019] Processor; and
[0020] A computer program, wherein the computer program is stored in a memory and is configured to be executed by a processor to implement the timing method according to the first aspect.
[0021] A fourth aspect of an embodiment of the present disclosure provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the timing method of the first aspect described above is implemented.
[0022] Compared with the prior art, the technical solution provided by the embodiments of the present disclosure has the following advantages:
[0023] The timing method, apparatus, device and medium provided by the embodiments of the present disclosure can create a timing thread in response to the startup of an application program, the timing thread being used to time multiple timing tasks in the application program, obtain at least one timing task, the at least one timing task respectively including a trigger time and a callback method, the callback method being a function interface of a preset operation triggered at the trigger time, and then for each timing task, call the timing thread to time the timing task, in response to the timing reaching the trigger time corresponding to the timing task, create a task thread corresponding to the timing task, execute the callback method corresponding to the timing task based on the task thread, and delete the task thread corresponding to the timing task after detecting that the timing task has been completed. Thus, multiple timing tasks in the application program can be timed through one timing thread, and the reuse of timing threads is realized. At the same time, a corresponding task thread is created for each timing task, and after the timing task is completed, the task thread corresponding to the timing task is deleted, thereby saving system resource usage and improving system performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0025] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0026] Figure 1 is a flow chart of a timing method provided by an embodiment of the present disclosure;
[0027] Figure 2 is a timing framework schematic diagram provided by an embodiment of the present disclosure;
[0028] Figure 3 is a flow chart of another timing method provided by an embodiment of the present disclosure;
[0029] Figure 4 is a structural schematic diagram of a timing device provided by an embodiment of the present disclosure;
[0030] Figure 5 It is a structural schematic diagram of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0031] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0032] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0033] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0034] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0035] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0036] Generally, in the existing timing execution logic design scheme of an application program including a timing function, when the delay operation tool provided by JAVA is used to implement the timing function of the application program, each time the application program starts a timing task, a new timing thread corresponding to the timing task will be started to perform timing, and after the timing task is completed, the timing thread corresponding to the timing task will also always exist. As the number of timing tasks increases, the number of timing threads in the system will also increase accordingly, and then there is a problem that the timing thread always occupies system resources, resulting in a decrease in system performance. In view of this problem, the embodiment of the present disclosure provides a timing method, which is described below in conjunction with a specific embodiment.
[0037] Figure 1It is a flowchart of a timing method provided by an embodiment of the present disclosure. The method can be executed by a timing device. The timing device can be implemented in software and / or hardware. The timing device can be configured in an electronic device, such as a server or a terminal or a server cluster, wherein the terminal can specifically include a mobile phone, a computer or a tablet computer, a vehicle-mounted terminal, etc.
[0038] like Figure 1 As shown, the timing method provided by the embodiment of the present disclosure includes the following steps.
[0039] S110 . In response to the application being started, a timing thread is created, where the timing thread is used to time a plurality of timing tasks in the application.
[0040] In an embodiment of the present disclosure, the electronic device creates a timing thread in response to the launch of an application.
[0041] In the embodiment of the present disclosure, the application program may be any program installed in the electronic device.
[0042] A timing thread is a thread used for timing, wherein the timing thread can time multiple timing tasks or all timing tasks in an application program, that is, all timing tasks in an application program correspond to only one timing thread.
[0043] Optionally, the application startup may be the first startup after the application is initialized, or the first startup of the application after the electronic device is restarted, etc., which is not limited here.
[0044] Specifically, in response to the start of the application, the electronic device can create a thread dedicated to timing, namely, a timing thread, through a handler Thread.
[0045] Among them, Handler can be understood as a message auxiliary class, which can send various message events to the message list (Handler.sendMessage) and handle corresponding message events (Handler.handleMessage).
[0046] S120: Acquire at least one timing task, where the at least one timing task includes a trigger time and a callback method, respectively. The callback method is a function interface of a preset operation that is triggered at the trigger time.
[0047] In an embodiment of the present disclosure, after creating a timing thread, the electronic device obtains at least one timing task, and the at least one timing task includes a trigger time and a callback method, and the callback method is a function interface of a preset operation triggered at the trigger time.
[0048] The timing can be the logic that the application needs to perform timing, such as timeout exit, on-point push, and other logic.
[0049] A timing task can be any task in an application that requires timing. The types of timing tasks can be synchronous callback timing, asynchronous callback timing, and loop timing.
[0050] Let's take a simple example to illustrate. For example, if the timing task is A telling B to wake me up at 6 o'clock in the morning, the synchronous callback timing means that B wakes A up at 6 o'clock in the morning; the asynchronous callback means that B is not free, so let C wake A up at 6 o'clock in the morning; the cyclic timing means that B calls A once every preset time period.
[0051] In the embodiment of the present disclosure, the trigger time may be understood as the time when the application triggers a preset operation.
[0052] Specifically, after creating a timing thread, the electronic device obtains a timing instance from a preset timing class factory, and then obtains at least one timing task according to the timing instance.
[0053] The preset timing class factory may be a factory that is preset and responsible for creating a timing instance of the timing class.
[0054] S130 . For each timing task, call a timing thread to time the timing task, and in response to the timing reaching a trigger time corresponding to the timing task, create a task thread corresponding to the timing task.
[0055] In an embodiment of the present disclosure, after acquiring at least one timing task, the electronic device calls a timing thread for each timing task to time the timing task, and creates a task thread corresponding to the timing task in response to the timing reaching a trigger time corresponding to the timing task.
[0056] In the embodiment of the present disclosure, the task thread is a thread used to execute a callback method corresponding to a timing task.
[0057] Specifically, after obtaining at least one timing task, the electronic device calls the timing thread to time the timing task for each timing task, and encapsulates the timing based on a preset mechanism, such as encapsulating the timing based on a handler mechanism. When the timing is completed, that is, when the timing reaches the trigger time corresponding to the timing task, a task thread corresponding to the timing task is created based on a preset thread pool such as CachedThreadPool.
[0058] S140, executing a callback method corresponding to the timing task based on the task thread.
[0059] In an embodiment of the present disclosure, after creating a task thread corresponding to the timing task, the electronic device executes a callback method corresponding to the timing task based on the task thread.
[0060] For example, a timing task of an application is to push an application message to the user at six o'clock in the morning. At this time, the trigger time corresponding to the timing task is six o'clock in the morning, the callback method is a function interface for pushing application messages to the user at six o'clock in the morning, and the task thread is used to execute the operation of pushing application messages to the user at six o'clock in the morning.
[0061] S150: After detecting that the timing task is completed, deleting the task thread corresponding to the timing task.
[0062] In some embodiments of the present disclosure, after the electronic device executes the callback method corresponding to the timing task based on the task thread, it detects the completion status of the timing task or the idle state of the task thread in real time, and deletes the task thread corresponding to the timing task after detecting that the timing task is completed.
[0063] In other embodiments of the present disclosure, after the electronic device executes the callback method corresponding to the timing task based on the task thread, it detects the usage status of the task thread in real time, and deletes the task thread corresponding to the timing task when it is detected that the task thread is in an idle state.
[0064] In an embodiment of the present disclosure, a timing thread can be created in response to the start of an application program. The timing thread is used to time multiple timing tasks in the application program, and at least one timing task is obtained. The at least one timing task includes a trigger time and a callback method, respectively. The callback method is a function interface of a preset operation that is triggered at the trigger time. Then, for each timing task, the timing thread is called to time the timing task. In response to the timing reaching the trigger time corresponding to the timing task, a task thread corresponding to the timing task is created. The callback method corresponding to the timing task is executed based on the task thread. After detecting that the timing task has been completed, the task thread corresponding to the timing task is deleted. Thus, multiple timing tasks in the application program can be timed through one timing thread, thereby realizing the reuse of timing threads. At the same time, a corresponding task thread is created for each timing task, and after the timing task is completed, the task thread corresponding to the timing task is deleted, thereby saving system resources and improving system performance.
[0065] Based on the above embodiment of the present disclosure, obtaining at least one timing task in S120 may specifically include: obtaining a timing instance from a preset timing class interface; performing preset processing on the timing instance to generate at least one timing task.
[0066] In the embodiments of the present disclosure, the preset timing class interface can be understood as the interface of the preset timing class factory. The preset timing class interface can be used to implement unified management of timing instances. For example, if a timing subclass of an application needs to be expanded or the data needs to be modified, the preset timing class factory can be directly modified to obtain the corresponding instance based on the tag, thereby increasing the flexibility of the program and implementing unified management of timing tasks.
[0067] In the embodiment of the present disclosure, the preset processing may include assignment processing, state adding processing, etc.
[0068] Furthermore, performing preset processing on the timing instance to generate at least one timing task may specifically include: performing assignment processing on the timing instance to obtain the timing instance after the assignment processing; adding a timing state identifier and a timing state judgment principle to the timing instance after the assignment processing to generate at least one timing task.
[0069] In the embodiments of the present disclosure, the assignment process may be understood as assigning corresponding timing parameters to the variables in the timing instance according to the timing requirements of the user or the timing parameters corresponding to the timing settings of the application.
[0070] Optionally, the timing status may include a status such as paused timing, timing in progress, etc., which is used to determine that the timing thread is timing the timing task.
[0071] The timing status flag may be an identifier for indicating the timing status, such as "1" for timing in progress and "0" for timing paused.
[0072] The timing state judgment principle can be understood as the logic used to judge the timing state.
[0073] Specifically, after acquiring the timing instance, the electronic device assigns the timing instance according to the timing parameters to obtain the assigned timing instance, and then adds the preset timing state identifier and timing state judgment principle to the assigned timing instance to generate at least one timing task.
[0074] In the embodiments of the present disclosure, unified management of the timing tasks corresponding to the timing instances can be achieved through a preset timing class interface, which facilitates operations such as updating and replacing the timing tasks. At the same time, corresponding timing status identifiers and timing status judgment principles are added to the timing instances, thereby realizing the judgment and query of the timing status.
[0075] In the embodiment of the present disclosure, after acquiring at least one timing task, the timing method may further include: encapsulating each timing task in the at least one timing task; and placing the encapsulated timing tasks into a preset task list.
[0076] Specifically, after acquiring at least one timing task, the electronic device encapsulates each timing task in the at least one timing task based on a preset mechanism such as a handler mechanism, and then puts the encapsulated timing task into a preset task list, wherein the preset task list can be a list such as a MessageQueue for storing messages sent based on a handler, such as encapsulated timing tasks.
[0077] In the embodiment of the present disclosure, each timing task is encapsulated and placed into a preset task list to ensure the security and non-modification of the timing task. At the same time, the preset task list can be used to sort the timing tasks according to their trigger time to ensure the timeliness of the execution of the timing tasks.
[0078] Furthermore, in S130, for each timing task, calling the timing thread to time the timing task may specifically include: determining the sequence of triggering time of each timing task in the preset task list; determining the target timing task based on the sequence; and calling the timing thread to time the target timing task.
[0079] In the disclosed embodiment, the order of timing tasks is determined according to the triggering time corresponding to the timing tasks. For example, there are three timing tasks stored in the task list, namely, timing task 1, timing task 2 and timing task 3, and their corresponding triggering times are 5 am, 3 pm and 10 am, respectively. Then, according to the early and late triggering times, the three timing tasks are sorted in the order of timing task 1, timing task 3 and timing task 2. Timing task 1 is determined as the target timing task, and the timing thread is called to time timing task 1 first, and then timing task 3 and timing task 2 are timed in sequence. During the timing of timing task 1, a new timing task is put into the timing task list, and the timing tasks are also sorted based on the triggering time according to the above method.
[0080] In the disclosed embodiment, the timing of the timing tasks can be realized in real time by determining the sequence of triggering time of each timing task in the preset task list, and then determining the target timing task based on the sequence, and then calling the timing thread to time the target timing task.
[0081] Figure 2 is a timing framework schematic diagram provided by an embodiment of the present disclosure, such as Figure 2As shown, all timing tasks in the application correspond to a timing thread, such as timing task 1, timing task 2 and timing task 3 correspond to a timing thread, and timing is performed through the timing thread. Then, the timing task list contains multiple timing tasks. According to the trigger time of the timing task, the order of the timing tasks is determined, and the timing thread is called to time the timing task. When the trigger time is reached, a new task thread is started to execute the callback method corresponding to the timing task, and the task thread is deleted after the timing task is executed. For example, for timing task 1 and timing task 2, when the trigger time of timing task 1 is reached, a new task thread 1 corresponding to timing task 1 is started, and the callback method corresponding to timing task 1 is executed based on task thread 1, and then task thread 1 is deleted after timing task 1 is executed; when the trigger time of timing task 2 is reached, a new task thread 2 corresponding to timing task 2 is started, and the callback method corresponding to timing task 2 is executed based on task thread 2, and then task thread 2 is deleted after timing task 2 is executed. Timing task 3 is in a state of waiting for execution, and will not be processed, and will not occupy system resources.
[0082] In the embodiment of the present disclosure, the timing method may further include: in response to a timing status query instruction of the timing task, acquiring a timing status corresponding to the timing task.
[0083] Specifically, when the electronic device receives the timing status query instruction, it responds to the timing status query instruction of the timing task, judges the timing status of the timing task according to the timing status judgment principle in the timing task, and compares the judgment result with the timing status identifier to determine the timing status corresponding to the timing task, thereby realizing the judgment and query of the timing status corresponding to the timing task, ensuring that the timing status can be obtained in real time.
[0084] In the embodiment of the present disclosure, the timing method may further include: in response to a change in the trigger time in the timing task, calling the timing thread to re-time the timing task based on the changed trigger time.
[0085] In the disclosed embodiment, the change of the trigger time can be understood as a change in the time for executing the preset operation. For example, the timing task is to ring for 10 seconds at 6 o'clock in the morning. After the trigger time is changed to 7 o'clock in the morning, the timing task is changed to ring for 10 seconds at 7 o'clock in the morning.
[0086] Specifically, when the electronic device responds to the change of the trigger time in the timing task, based on the changed trigger time, the timing thread is called to re-time the timing task, thereby ensuring the accuracy of the execution of the timing task.
[0087] Figure 3 is a flow chart of another timing method provided by an embodiment of the present disclosure, such as Figure 3As shown, the timing method may include the following steps:
[0088] S310: In response to the application being started, create a timing thread.
[0089] S320: Obtain a timing instance from a preset timing class interface, perform preset processing on the timing instance, and generate at least one timing task.
[0090] S330: For each timing task, call a timing thread to time the timing task, and encapsulate the timing based on a preset mechanism.
[0091] In the disclosed embodiments, the electronic device can encapsulate timing based on a preset mechanism such as a handler mechanism to ensure the uniqueness and invariance of the timing corresponding to each timing task.
[0092] In the embodiment of the present disclosure, in response to the timing reaching the trigger time corresponding to the timing task, S340-S350 are executed, in response to the timing status query instruction of the timing task, S360 is executed; in response to the timing cancel instruction of the timing task, S370 is executed.
[0093] S340: In response to the timing reaching the trigger time corresponding to the timing task, a task thread corresponding to the timing task is created, and a callback method corresponding to the timing task is executed based on the task thread.
[0094] S350: After detecting that the timing task is completed, deleting the task thread corresponding to the timing task.
[0095] S360: In response to the timing status query instruction of the timing task, obtain the timing status corresponding to the timing task.
[0096] S370: In response to the cancel timing instruction of the timing task, stop timing the timing task.
[0097] In an embodiment of the present disclosure, the electronic device is able to create a timing thread in response to the start of an application, obtain a timing instance from a preset timing class interface, perform preset processing on the timing instance, generate at least one timing task, call the timing thread for each timing task to time the timing task, and encapsulate the timing based on a preset mechanism to ensure the uniqueness and invariance of the timing corresponding to each timing task, and perform different operations in response to different instructions. In response to the timing reaching the trigger time corresponding to the timing task, a task thread corresponding to the timing task is created, and a callback method corresponding to the timing task is executed based on the task thread. After detecting that the timing task has been executed, the task thread corresponding to the timing task is deleted, and in response to a timing status query instruction of the timing task, the timing status corresponding to the timing task is obtained. In response to a cancel timing instruction of the timing task, the timing of the timing task is stopped, thereby saving system resources and improving system performance, thereby achieving flexibility in the execution of timing tasks.
[0098] Figure 4 1 is a schematic diagram of a timing device provided in an embodiment of the present disclosure. The timing device in the embodiment of the present disclosure may be provided in an electronic device, and the electronic device may be a server or a terminal or a server cluster, wherein the terminal may specifically include a mobile phone, a computer or a tablet computer, a vehicle-mounted terminal, etc., which is not limited here.
[0099] like Figure 4 As shown, the timing device 400 may include a first creation module 410 , a task acquisition module 420 , a second creation module 430 , a task execution module 440 and a thread deletion module 450 .
[0100] The first creation module 410 may be used to create a timing thread in response to the application being started, where the timing thread is used to time multiple timing tasks in the application.
[0101] The task acquisition module 420 can be used to acquire at least one timing task. The at least one timing task includes a trigger time and a callback method. The callback method is a function interface of a preset operation that is triggered at the trigger time.
[0102] The second creation module 430 may be used to call a timing thread for each timing task to time the timing task, and create a task thread corresponding to the timing task in response to the timing reaching a trigger time corresponding to the timing task.
[0103] The task execution module 440 may be used to execute a callback method corresponding to a timing task based on a task thread.
[0104] The thread deletion module 450 may be configured to delete the task thread corresponding to the timing task after detecting that the timing task has been completed.
[0105] In an embodiment of the present disclosure, a timing thread can be created in response to the start of an application program. The timing thread is used to time multiple timing tasks in the application program, and at least one timing task is obtained. The at least one timing task includes a trigger time and a callback method, respectively. The callback method is a function interface of a preset operation that is triggered at the trigger time. Then, for each timing task, the timing thread is called to time the timing task. In response to the timing reaching the trigger time corresponding to the timing task, a task thread corresponding to the timing task is created. The callback method corresponding to the timing task is executed based on the task thread. After detecting that the timing task has been completed, the task thread corresponding to the timing task is deleted. Thus, multiple timing tasks in the application program can be timed through one timing thread, thereby realizing the reuse of timing threads. At the same time, a corresponding task thread is created for each timing task, and after the timing task is completed, the task thread corresponding to the timing task is deleted, thereby saving system resources and improving system performance.
[0106] In some embodiments of the present disclosure, the task acquisition module 420 may include an instance acquisition unit 4201 and a preprocessing unit 4202 .
[0107] The instance acquisition unit 4201 may be configured to acquire a timing instance from a preset timing class interface.
[0108] The pre-processing unit 4202 may be configured to perform preset processing on the timing instance and generate at least one timing task.
[0109] In some embodiments of the present disclosure, the pre-processing unit 4202 may assign a sub-unit and a state adding sub-unit.
[0110] The assignment subunit may be used to perform assignment processing on the timing instance to obtain the timing instance after the assignment processing.
[0111] The state adding subunit can be used to add a timing state identifier and a timing state judgment principle to the timing instance after the value assignment process, and generate at least one timing task.
[0112] In some embodiments of the present disclosure, the timing device 400 may further include a task encapsulation module 460 and a task list module 470 .
[0113] The task encapsulation module 460 may be used to encapsulate each timing task in at least one timing task.
[0114] The task list module 470 can be used to put the packaged timing tasks into a preset task list.
[0115] In some embodiments of the present disclosure, the second creation module 430 may include a sequence determination unit 4301 , a task determination unit 4302 , and a task timing unit 4303 .
[0116] The sequence determination unit 4301 may be used to determine the sequence of triggering time of each timing task in the preset task list.
[0117] The task determination unit 4302 may be configured to determine target timing tasks based on a sequential order.
[0118] The task timing unit 4303 may be used to call a timing thread to perform timing on a target timing task.
[0119] In some embodiments of the present disclosure, the timing device 400 may further include a status query module 480 .
[0120] The status query module 480 may be configured to respond to a timing status query instruction of a timing task and obtain a timing status corresponding to the timing task.
[0121] In some embodiments of the present disclosure, the timing device 400 may further include a time changing module 490 .
[0122] The time change module 490 may be used to respond to a change in the trigger time in the timing task and, based on the changed trigger time, call the timing thread to re-time the timing task.
[0123] It should be noted that Figure 4 The timing device 400 shown can execute each step in the above method embodiment and realize each process and effect in the above method embodiment, which will not be described in detail here.
[0124] Figure 5 A schematic structural diagram of an electronic device provided by an embodiment of the present disclosure is shown.
[0125] In the disclosed embodiment, Figure 5 The electronic device shown may be a server or a terminal or a server cluster, wherein the terminal may specifically include a mobile phone, a computer or a tablet computer, a vehicle-mounted terminal, etc., which is not limited here.
[0126] like Figure 5 As shown, the electronic device may include a processor 510 and a memory 520 storing computer program instructions.
[0127] Specifically, the processor 510 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0128] The memory 520 may include a large capacity memory for information or instructions. By way of example and not limitation, the memory 520 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a tape, or a universal serial bus (USB) drive, or a combination of two or more of these. Where appropriate, the memory 520 may include a removable or non-removable (or fixed) medium. Where appropriate, the memory 520 may be inside or outside the integrated gateway device. In a particular embodiment, the memory 520 is a non-volatile solid-state memory. In a particular embodiment, the memory 520 includes a read-only memory (ROM). Where appropriate, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (Electrically Erasable Programmable ROM, EEPROM), an electrically rewritable ROM (EAROM), or a flash memory, or a combination of two or more of these.
[0129] The processor 510 reads and executes the computer program instructions stored in the memory 520 to perform the steps of the timing method provided in the embodiment of the present disclosure.
[0130] In one example, the electronic device may further include a transceiver 530 and a bus 540. Figure 5 As shown, the processor 510, the memory 520 and the transceiver 530 are connected via a bus 540 and communicate with each other.
[0131] The bus 540 includes hardware, software, or both. For example, but not limitation, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industrial Standard Architecture (ISA) bus, an InfiniBand interconnect, a Low Pin Count (LPC) bus, a Memory bus, a MicroChannel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local Bus (VLB) bus, or other suitable buses or a combination of two or more of these. Where appropriate, the bus 540 may include one or more buses.
[0132] The embodiment of the present disclosure further provides a computer-readable storage medium, which may store a computer program. When the computer program is executed by a processor, the processor implements the timing method provided by the embodiment of the present disclosure.
[0133] The above-mentioned storage medium may, for example, include a memory 520 of computer program instructions, and the above-mentioned instructions may be executed by the processor 510 of the electronic device to complete the timing method provided in the embodiment of the present disclosure. Optionally, the storage medium may be a non-temporary computer-readable storage medium, for example, the non-temporary computer-readable storage medium may be a ROM, a random access memory (Random Access Memory, RAM), a compact disc read-only memory (Compact Disc ROM, CD-ROM), a magnetic tape, a floppy disk, and an optical data storage device, etc.
[0134] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the term "comprising" is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.
[0135] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A timing method, characterized in that: The method comprises: In response to the application being started, creating a timing thread, the timing thread being used to time a plurality of timing tasks in the application; Acquire at least one timing task, wherein the at least one timing task includes a trigger time and a callback method, and the callback method is a function interface of a preset operation triggered at the trigger time; For each timing task, calling the timing thread to time the timing task, and in response to the timing reaching the trigger time corresponding to the timing task, creating a task thread corresponding to the timing task; Execute the callback method corresponding to the timing task based on the task thread; After detecting that the timing task is completed, the task thread corresponding to the timing task is deleted.
2. The method according to claim 1, characterized in that The acquiring of at least one timing task comprises: Get the timing instance from the preset timing class interface; The timing instance is preset and processed to generate at least one timing task.
3. The method according to claim 2, characterized in that The presetting process of the timing instance to generate at least one timing task includes: Performing value assignment processing on the timing instance to obtain a timing instance after value assignment processing; A timing state identifier and a timing state judgment principle are added to the timing instance after the value assignment process to generate at least one timing task.
4. The method according to claim 1, characterized in that: After acquiring at least one timing task, the method further includes: Encapsulating each of the at least one timing task; Put the encapsulated timing tasks into the preset task list.
5. The method according to claim 4, characterized in that For each timing task, calling the timing thread to time the timing task includes: Determine the order of triggering time of each timing task in the preset task list; Based on the sequence, determining a target timing task; The timing thread is called to perform timing on the target timing task.
6. The method according to claim 1, characterized in that The method further comprises: In response to the timing status query instruction of the timing task, the timing status corresponding to the timing task is acquired.
7. The method according to claim 1, characterized in that The method further comprises: In response to a change in the trigger time in the timing task, the timing thread is called to re-time the timing task based on the changed trigger time.
8. A timing device, characterized in that: include: A first creation module, configured to create a timing thread in response to the application being started, wherein the timing thread is configured to time a plurality of timing tasks in the application; A task acquisition module, used to acquire at least one timing task, wherein the at least one timing task includes a trigger time and a callback method, and the callback method is a function interface of a preset operation triggered at the trigger time; A second creation module is used to call the timing thread for each timing task to time the timing task, and create a task thread corresponding to the timing task in response to the timing reaching the trigger time corresponding to the timing task; A task execution module, used for executing the callback method corresponding to the timing task based on the task thread; The thread deletion module is used to delete the task thread corresponding to the timing task after detecting that the timing task has been executed.
9. An electronic device, characterized in that: include: Memory; processor; as well as Computer programs; The computer program is stored in the memory and is configured to be executed by the processor to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
