Master-slave task state synchronization method and device based on lock and time signal
By employing a master-slave task state synchronization method based on locks and time signals in the SIM connection platform, and utilizing plug-ins and time signal recorders, the performance overhead and synchronization miss issues of master-slave task state synchronization are resolved, achieving low-latency and high-performance state synchronization.
Patent Information
- Application Number
- CN202510959999.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-11
- Publication Date
- 2025-10-17
AI Technical Summary
In SIM connectivity platforms, the synchronization of the master and slave tasks suffers from high performance overhead and state asynchrony, especially when the master task polls frequently or sparsely, resulting in performance impact and missed synchronization.
A master-slave task state synchronization method based on locks and time signals is adopted. The master task and slave task are connected in the form of a plug-in, and the slave task is executed concurrently. The master state execution lock and time signal recorder are used to control the state update of the master task, avoiding frequent start-up and destruction and saving resources.
It achieves low-latency and high-performance synchronization of master and slave tasks, saving application threads and database resources, and ensuring state consistency and efficient synchronization.
Smart Images

Figure CN120803760A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the field of data processing, and particularly relates to a master-slave task state synchronization method and device based on a lock and a time signal. BACKGROUND
[0002] The statements in this section merely provide background information related to the present application and do not necessarily constitute the prior art.
[0003] A large number of and different kinds of tasks are contained in the SIM connection platform, which are divided into two levels of master tasks and slave tasks. Among them, the master task is to summarize information, and the slave task is to record various information required for handling in detail. The relationship between the master task and the slave task is 1:N.
[0004] Both the master task and the slave task have states. The master task is only marked as completed when all the slave tasks are completed. The slave tasks are executed in a concurrent manner. The timing for the master task to check whether all the slave tasks are completed is currently a technical difficulty. If the master task checks the slave tasks too frequently, that is, the polling is too frequent, the performance of the SIM connection platform will be affected, resulting in a problem of large performance overhead. If the master task checks the slave tasks too infrequently, that is, the polling is too sparse, the problem of different synchronization of the two levels of states and the problem of missing the timing for checking the completion of the slave task may occur. SUMMARY
[0005] In order to solve the technical problems in the background art, the present application provides a master-slave task state synchronization method and device based on a lock and a time signal, which can realize low-delay synchronization state and high-performance synchronization state of the master-slave tasks.
[0006] In order to achieve the above-mentioned purpose, the present application adopts the following technical solutions: The first aspect of the present application provides a master-slave task state synchronization method based on a lock and a time signal.
[0007] A master-slave task state synchronization method based on a lock and a time signal, comprising: The master state executor is connected between the master task and the slave task in the form of a plug-in; All the slave tasks are executed concurrently. When each slave task is completed, a transaction is submitted first, and then the master state executor is called; The time in the master state earliest execution time signal recorder is reset to the current time plus a set time; It is judged whether the master state execution lock is successfully locked. If not, the master state executor is ended; When the master state execution lock is successfully locked, it is judged whether the current time is not later than the time recorded in the master state earliest execution time signal recorder, if yes, the master state executor delays for a set time and then judges again whether the current time is not later than the time recorded in the master state earliest execution time signal recorder, otherwise, the master state execution lock is unlocked; It is judged whether all the slave tasks are completed, if yes, the master task state is changed to completed, and the master state executor is ended; otherwise, the master state executor is directly ended.
[0008] As an embodiment, the first space and the second space are applied in the memory of the master state executor, and are used for storing the default random value and the state of the master state execution lock respectively.
[0009] As an embodiment, the value in the second space is 0 by default, and 0 represents that the lock is not locked; when the value in the second space is 1, it represents that the lock is locked.
[0010] As an embodiment, whether the master state execution lock is successfully locked is judged according to the values in the first space and the second space.
[0011] As an embodiment, the condition that the master state execution lock is successfully locked is: When the value in the second space is 0 and the value in the first space is the same as the value in the first space taken by the slave task before, the value in the first space is overwritten by the random value defined by the slave task.
[0012] As an embodiment, the third space is also applied in the memory of the master state executor, and is used for storing the time recorded in the master state earliest execution time signal recorder.
[0013] The second aspect of the present application provides a master-slave task state synchronization device based on a lock and a time signal.
[0014] A master-slave task state synchronization device based on a lock and a time signal, comprising: A plug-in access module, which is used for accessing the master state executor in the form of a plug-in between the master task and the slave task; A master state executor calling module, which is used for executing all the slave tasks in parallel, and submitting a transaction before calling the master state executor after each slave task is completed; A time resetting module, which is used for resetting the time in the master state earliest execution time signal recorder to the current time plus a set time; A lock success judging module, which is used for judging whether the master state execution lock is successfully locked, and ending the master state executor if not; The time comparison module is used to determine whether the current time is not later than the time recorded in the earliest execution time signal recorder of the main state when the main state execution lock is successfully locked. If so, the main state executor will delay for a set time and then determine again whether the current time is not later than the time recorded in the earliest execution time signal recorder of the main state. Otherwise, the main state execution lock is unlocked. The slave task completion judgment module is used to judge whether all slave tasks have been completed. If so, the master task state is changed to completed and the master state executor is terminated; otherwise, the master state executor is directly terminated.
[0015] A third aspect of the present invention provides a computer-readable storage medium.
[0016] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the master-slave task state synchronization method based on locks and time signals as described above.
[0017] A fourth aspect of the present invention provides a computer program product.
[0018] A computer program product includes a computer program / instruction, which, when executed by a processor, implements the steps in the master-slave task state synchronization method based on locks and time signals as described above.
[0019] A fifth aspect of the present invention provides an electronic device.
[0020] An electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps of the master-slave task state synchronization method based on locks and time signals are implemented.
[0021] Compared with the prior art, the present invention has the following beneficial effects: The present invention uses a plug-in to install a master state executor without intruding on the business logic of the master and slave themselves; and uses a master state execution lock to resist traffic peaks, ensuring that when there are many slave tasks that need to execute subsequent master tasks, only one master task is released to proceed, saving application thread resources and database computing resources; uses a master state earliest execution time signal recorder to record the time to complete the delayed operation of the master task, so that the master task is not frequently started and destroyed, saving application thread resources and database computing resources, and realizing a low-latency synchronization state, a high-performance synchronization state, and a synchronization state that needs to be awakened again of the master and slave tasks.
[0022] Advantages of additional aspects of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The accompanying drawings, which form a part of this specification, are included to provide a further understanding of the application and are incorporated in and constitute a part of this specification. The embodiments of the application, together with its
[0024] Figure 1 is a flow chart of a master-slave task state synchronization method based on a lock and a time signal according to an embodiment of the application; Figure 2 is a process chart of a master-slave task state synchronization method based on a lock and a time signal according to an embodiment of the application; Figure 3 is a structure schematic diagram of a master-slave task state synchronization device according to an embodiment of the application. DETAILED DESCRIPTION
[0025] The application will be further described below in connection with the drawings and embodiments.
[0026] It should be noted that the following detailed description is illustrative only, and is intended to provide further description of the application. Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs.
[0027] It should be noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of example embodiments in accordance with the present application. As used herein, the singular forms "a", "an" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "comprises" and / or "comprising," when used in this specification, specify the presence of stated features, steps, operations, elements, components, and / or groups thereof, but do not preclude the presence or addition of one or more other features, steps, operations, elements, components, and / or groups thereof.
[0028] Terminology: SIM connectivity platform refers to a platform for managing and connecting SIM cards, mainly used for the management and communication of Internet of Things (IoT) devices. These platforms provide a series of functions, including device access, data transmission, remote control and secure communication, etc., helping enterprises and developers to more effectively manage and use SIM cards.
[0029] In the embodiments of the application, the effect of requiring re-awakening synchronization state can be achieved. Specifically, one or more sub-tasks are just completed → mark "the master task state may need to be synchronized". Each time a sub-task is completed, a "wake-up signal" is set to tell the executor: "Now the master task state should be checked". In this way, it is ensured that only when it is really necessary to synchronize the master task, the master task is attempted to be synchronized, avoiding meaningless waste.
[0030] Embodiment one According to Figure 1 and Figure 2The embodiment of the application provides a master-slave task state synchronization method based on a lock and a time signal, which comprises the following steps: S101: a master state executor is connected between a master task and a slave task in the form of a plug-in.
[0031] The master state executor is installed in the form of a plug-in, so that the business logic of the master task and the slave task is not invaded, and the connection and debugging are facilitated.
[0032] S102: all slave tasks are executed concurrently, and a transaction is submitted after each slave task is completed, and then the master state executor is called.
[0033] It should be noted that the concurrent slave task and the master state executor run in a sub-process.
[0034] In the specific implementation process, a first space and a second space are applied for in the memory of the master state executor, and are used for storing a default random value and a state representing a master state execution lock respectively.
[0035] The first space stores a default random value.
[0036] The value in the second space is 0 by default, and 0 represents that the lock is not locked; when the value in the second space is 1, it represents that the lock is locked.
[0037] S103: the time in the master state earliest execution time signal recorder is reset to the current time plus a set time (for example, 1s, which can be set according to the actual situation).
[0038] A third space is also applied for in the memory of the master state executor, and is used for storing the time recorded by the master state earliest execution time signal recorder. The third space can store a time value. The slave task can constantly update the value of the memory space, and the master state executor listens to the space field, and the purpose is to make the thread of the master state executor not be destroyed and the lock not be released, so that the running state is maintained.
[0039] Therefore, the memory of the master state executor has the first space, the second space and the third space, and simultaneously has a time delay device and a listener.
[0040] The master state earliest execution time signal recorder completes the delay operation of the master task by recording the time, so that the master task is not frequently started and destroyed, and the application thread resource and the database calculation resource are saved.
[0041] S104: whether the master state execution lock is successfully locked is judged, and if not, the master state executor is ended.
[0042] Whether the master state execution lock is successfully locked is judged according to the value in the first space and the value in the second space.
[0043] As an implementation, the condition for the master state execution lock to be successfully locked is: When the value in the second space is 0 and the value of the first space is the same as the value of the first space taken out before the task, the value of the first space is overwritten as the custom random value of the task.
[0044] The process of each lock is: First, get the random value of the first space of the master state executor, and also customize a random value from the task itself. The update logic is that when the second space is 0 and the value of the first space is the same as the value of the first space taken out before, the value of the first space is overwritten as the custom random value of the task, and the second space is set to 1.
[0045] The process of unlocking is to set the second space to 0.
[0046] The function of the master state execution lock is to resist traffic flood and ensure that when there are many subsequent master tasks to be executed after a large number of slave tasks are executed, only one master task is released to proceed, saving application thread resources and database computing resources.
[0047] S105: When the master state execution lock is successfully locked, it is judged whether the current time is not later than the time recorded in the master state earliest execution time signal recorder. If so, the master state executor delays for a set time and then judges again whether the current time is not later than the time recorded in the master state earliest execution time signal recorder. Otherwise, the master state execution lock is unlocked.
[0048] The master state execution lock of the embodiment does not need to be judged when it is locked, avoiding the problem that concurrent judgment and locking may occur when the judgment and locking are performed in sequence.
[0049] The business logic of the master task is executed after the master state execution lock is unlocked, avoiding the problem that a new master task may be missed after the unlocking process.
[0050] S106: It is judged whether all slave tasks have been completed. If so, the master task state is changed to completed, and the master state executor is ended. Otherwise, the master state executor is directly ended.
[0051] For example, the master task table (master_tasks): task_id | status| created_at --------+-----------+--------------------- 1| PENDING| 2025-06-27 10:00:00; 2| PENDING| 2025-06-27 10:05:00; From the task table (slave_tasks): id | master_task_id | status| finished_at ---+----------------+------------+--------------------- 1| 1| COMPLETED| 2025-06-27 10:10:05; 2| 1| COMPLETED| 2025-06-27 10:11:00; 3| 1| COMPLETED| 2025-06-27 10:12:30; 4| 2| COMPLETED| 2025-06-27 10:15:00; 5| 2| PENDING| 2025-06-27 10:15:00; Master task 1 has three slave tasks, all of which are completed. Master task 2 has one completed slave task and one pending slave task.
[0052] After processing: task_id | status| created_at --------+------------+--------------------- 1| COMPLETED| 2025-06-27 10:00:00; 2| PENDING| 2025-06-27 10:05:00; As can be seen, master task 1 is marked as completed.
[0053] This embodiment installs the master state executor in the form of a plug-in, without invading the business logic of the master and slave themselves. Moreover, it uses the master state execution lock to resist traffic floods, ensuring that when there are many slave tasks in front of the subsequent master task that need to be executed, the subsequent master task is only released to proceed, saving application thread resources and database computing resources. It uses the master state earliest execution time signal recorder to record the time to complete the delay operation of the master task, so that the master task is not frequently started and destroyed, saving application thread resources and database computing resources, and achieving low-latency synchronization state, high-performance synchronization state, and on-demand wake-up synchronization state of master and slave tasks.
[0054] Embodiment Two According toFigure 3 The application provides a master-slave task state synchronization device based on a lock and a time signal, and specifically comprises the following modules. The plug-in access module 301 is used for accessing the master state executor in the form of a plug-in between the master task and the slave task. The master state executor calling module 302 is used for executing all the slave tasks concurrently, and submitting a transaction before calling the master state executor after each slave task is completed. The time resetting module 303 is used for resetting the time in the master state earliest execution time signal recorder to the current time plus a set time. The lock success judging module 304 is used for judging whether the master state execution lock is successfully locked, and if not, ending the master state executor. The time comparing module 305 is used for judging whether the current time is not later than the time recorded in the master state earliest execution time signal recorder when the master state execution lock is successfully locked, if yes, the master state executor delays a set time and then judges again whether the current time is not later than the time recorded in the master state earliest execution time signal recorder, or else, the master state execution lock is unlocked. The slave task completion judging module 306 is used for judging whether all the slave tasks are completed, if yes, changing the master task state to completion and ending the master state executor, or else, directly ending the master state executor.
[0055] It should be noted that the modules in the embodiment of the application correspond to the steps in the above-mentioned embodiment one by one, and the specific implementation process is the same, which will not be repeated here.
[0056] Embodiment three The embodiment provides a computer readable storage medium, which stores a computer program, and the program is executed by a processor to realize the steps in the master-slave task state synchronization method based on a lock and a time signal.
[0057] Embodiment four A computer program product comprises computer programs / instructions, which are executed by a processor to realize the steps in the master-slave task state synchronization method based on a lock and a time signal.
[0058] Embodiment five The embodiment provides an electronic device, which comprises a memory, a processor and a computer program stored in the memory and executable on the processor, and the processor executes the program to realize the steps in the master-slave task state synchronization method based on a lock and a time signal.
[0059] The electronic device in this embodiment includes a central processing unit (CPU), which can perform various appropriate actions and processes based on programs stored in a read-only memory (ROM) or programs loaded from a storage unit into a random access memory (RAM). The RAM also stores various programs and data required for system operation. The CPU, ROM, and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.
[0060] The following components are connected to the I / O interface: an input section including a keyboard and mouse; an output section including cathode ray tubes (CRTs), liquid crystal displays (LCDs), and speakers; a storage section including a hard disk; and a communication section including network interface cards such as local area network (LAN) cards and modems. The communication section performs communication processing via a network such as the Internet. A drive is also connected to the I / O interface as needed. Removable media such as magnetic disks, optical disks, magneto-optical disks, and semiconductor memories are installed in the drive as needed, allowing computer programs read from these media to be installed in the storage section as needed.
[0061] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via a communication portion, and / or installed from a removable medium. When the computer program is executed by a central processing unit, the various functions defined in the apparatus of the present application are performed.
[0062] The present invention is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products of the embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams and the combination of processes and / or blocks in the flowcharts and / or block diagrams can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0063] The above merely provides the preferred embodiments of the present application, and is not used to limit the present application. For those skilled in the art, the present application can have various modifications and changes. Any modifications, equivalent replacements, improvements, etc. made within the principles and technical scope of the present application shall fall into the scope of the present application.
Claims
1. A master-slave task state synchronization method based on lock and time signal, characterized in that: include: Connect the master state executor as a plug-in between the master task and the slave task; Execute all slave tasks concurrently. When each slave task is completed, commit the transaction first and then call the master state executor. Reset the time in the main state earliest execution time signal recorder to the current time plus the set time; Determine whether the main state execution lock is locked successfully. If it fails, end the main state executor; When the main state execution lock is locked successfully, it is determined whether the current time is not later than the time recorded in the main state earliest execution time signal recorder. If so, the main state executor delays the set time and then determines again whether the current time is not later than the time recorded in the main state earliest execution time signal recorder. Otherwise, the main state execution lock is unlocked. Determine whether all slave tasks have been completed. If so, change the master task status to completed and end the master state executor; otherwise, end the master state executor directly.
2. The master-slave task state synchronization method based on lock and time signal according to claim 1, characterized in that: In the memory of the main state executor, a first space and a second space are allocated for storing the default value at any time and representing the state of the main state execution lock respectively.
3. The master-slave task state synchronization method based on lock and time signal according to claim 2, characterized in that: The default value in the second space is 0, which means it is unlocked; When the value in the second space is 1, it means it is locked.
4. The master-slave task state synchronization method based on lock and time signal according to claim 2, characterized in that: Whether the main state execution lock is locked successfully is determined based on the values in the first space and the second space.
5. The master-slave task state synchronization method based on lock and time signal according to claim 2, characterized in that: The conditions for successfully locking the main state execution lock are: When the value in the second space is 0 and the value in the first space is the same as the value in the first space taken from the task before, the value in the first space is overwritten with the custom random value from the task.
6. The master-slave task state synchronization method based on lock and time signal according to claim 1, characterized in that: A third space is also allocated in the memory of the main state executor to store the time recorded by the main state earliest execution time signal recorder.
7. A master-slave task state synchronization device based on lock and time signal, characterized in that: include: The plug-in access module is used to connect the main state executor between the master task and the slave task in the form of a plug-in; The master state executor calls the module, which is used to execute all slave tasks concurrently. When each slave task is completed, the transaction is committed first, and then the master state executor is called; A time reset module, which is used to reset the time in the main state earliest execution time signal recorder to the current time plus the set time; The lock success judgment module is used to judge whether the main state execution lock is locked successfully. If it fails, the main state executor is terminated; The time comparison module is used to determine whether the current time is not later than the time recorded in the earliest execution time signal recorder of the main state when the main state execution lock is successfully locked. If so, the main state executor will delay for a set time and then determine again whether the current time is not later than the time recorded in the earliest execution time signal recorder of the main state. Otherwise, the main state execution lock is unlocked. The slave task completion judgment module is used to judge whether all slave tasks have been completed. If so, the master task state is changed to completed and the master state executor is terminated; otherwise, the master state executor is directly terminated.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the master-slave task state synchronization method based on locks and time signals are implemented as described in any one of claims 1 to 6.
9. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the steps of the master-slave task state synchronization method based on locks and time signals are implemented as described in any one of claims 1 to 6.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the master-slave task state synchronization method based on locks and time signals are implemented as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Task scheduling method, device and equipment and computer storage medium
CN111666141A
Distributed timed task processing method and system
CN111722934A
Distributed lock delay processing method and device, equipment and medium
CN116820790A
Data processing method and device, electronic equipment and storage medium
CN120104643A
Computer-implemented method of distributed management of locks, apparatus for distributed management of locks and computer program product
CN120112894A