SCA service concurrency control method and device based on user-defined annotation

Through the combination of custom annotations and Redis distributed locks, efficient and independent concurrent control in the SCA business system is achieved, solving the problems of strong invasiveness and data inconsistency in the existing technology, and improving system performance and data integrity.

CN120256042APending Publication Date: 2025-07-04SECZONE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510195403.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-21
Publication Date
2025-07-04

AI Technical Summary

Technical Problem

Existing concurrency control tools need to intrude into business code in SCA services, resulting in complex integration. Concurrency control cannot fully match long-term processing of business requests, which can easily cause interruptions or data errors, especially in distributed cluster environments, data inconsistency problems are difficult to solve.

Method used

Intercept tasks through custom annotations, and use Redis distributed lock concurrency control methods, including task interception, distributed lock settings, task queue management and lock release, to achieve efficient and independent concurrent control logic and reduce intrusion into business code.

Benefits of technology

Effectively maintain the consistency and integrity of SCA business data, improve system performance, reduce intrusion into business code, and improve system stability and flexibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120256042A_ABST
    Figure CN120256042A_ABST
Patent Text Reader

Abstract

The invention discloses an SCA service concurrency control method and device based on a user-defined annotation, the user-defined annotation is created in an SCA service system, and the concurrency control method comprises the following steps: intercepting a task marked with the user-defined annotation, and obtaining an annotation parameter of the user-defined annotation; adding a distributed lock to the task by utilizing Redis according to the acquired annotation parameter, and setting an initial value of effective time for the distributed lock; adding the task added with the distributed lock into a task queue; monitoring the effective time of the distributed lock of each task in the task queue, and prolonging the effective time of the distributed lock of the task which is not executed completely before the distributed lock is invalid; and releasing the distributed lock of the executed task by utilizing Redis. According to the SCA service concurrency control method based on the user-defined annotation, efficient and independent concurrency control logic is achieved in an annotation mode, invasion to service codes can be effectively reduced, and consistency and integrity of SCA service data can be effectively kept.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of SCA service concurrent control, and in particular to an SCA service concurrent control method and device based on custom annotations. Background Art

[0002] In the process of implementing SCA services, since information between different JVM instances cannot be directly shared, especially in a distributed cluster environment, this easily leads to data inconsistency or anomalies. Therefore, it is necessary to lock the service during data interaction to ensure the integrity of the service process and the atomicity of operations. However, existing concurrent control tools need to invade business code, resulting in complex integration problems. Moreover, some business requests take a long time to process, leading to business interruptions or data errors caused by concurrency. Existing concurrent control tools cannot fully meet the business requirements. Summary of the Invention

[0003] The purpose of the present invention is to provide an SCA service concurrent control method and device based on custom annotations, which can implement efficient and independent concurrent control logic through annotations, effectively reduce the invasion of business code to improve the overall performance of the system, and effectively maintain the consistency and integrity of SCA service data.

[0004] To achieve the above purpose, the present invention discloses an SCA service concurrent control method based on custom annotations. A custom annotation is created in the SCA service system, and the concurrent control method includes: 101. Intercept tasks marked with custom annotations and obtain the annotation parameters of the custom annotations; 102. Use Redis to add a distributed lock to the task according to the obtained annotation parameters and set an initial value for the valid time of the distributed lock; 103. Add the task with the distributed lock added to the task queue; 104. Monitor the valid time of the distributed lock of each task in the task queue and extend the valid time of the distributed lock of uncompleted tasks before the distributed lock becomes invalid; 105. Use Redis to release the distributed lock of the completed task.

[0005] Further, after "using Redis to release the distributed lock of the completed task", it further includes: Record the obtained annotation parameters, adding the distributed lock, and abnormal situations during task execution to the log.

[0006] Further, the annotation parameters include: parameter identification subscript, number of retry attempts obtained, lock type, and lock release time.

[0007] Further, the distributed lock includes a custom lock, and the lock parameters of the custom lock include a task lock key, a valid duration, thread execution data, and the number of attempts.

[0008] Further, the "intercepting tasks marked with a custom annotation and obtaining the annotation parameters of the custom annotation" includes: Scanning and intercepting tasks marked with a custom annotation using an aspect interceptor; Registering the intercepted tasks into a concurrency control container; Extracting the annotation parameters of the custom annotation and the execution parameters of the tasks.

[0009] Further, the "monitoring the valid time of the distributed lock of each task in the task queue" includes: Judging whether the valid time of the distributed lock of a task is zero. If it is zero, the task is removed from the task queue; Judging whether the execution times of a task are greater than the execution retry times. If the judgment is yes, the task is removed from the task queue.

[0010] Further, the "extending the valid time of the distributed lock of an uncompleted task before the distributed lock becomes invalid" includes: Judging whether the valid time of the distributed lock of a task is less than one-third of the initial value of the valid time. If the judgment is yes, the valid time of the distributed lock is increased by a preset extension time.

[0011] To achieve the above object, the present invention discloses an SCA service concurrency control device based on a custom annotation, which includes: An interception module, configured to intercept tasks marked with a custom annotation and obtain the annotation parameters of the custom annotation; A first addition module, configured to add a distributed lock to a task using Redis according to the obtained annotation parameters and set an initial value for the valid time of the distributed lock; A second addition module, configured to add the task with the added distributed lock to the task queue; A monitoring module, configured to monitor the valid time of the distributed lock of each task in the task queue and extend the valid time of the distributed lock of an uncompleted task before the distributed lock becomes invalid; A release module, configured to release the distributed lock of a completed task using Redis.

[0012] To achieve the above object, the present invention discloses an electronic device, which includes: One or more processors; One or more memories for storing one or more programs, which when executed by the processor cause the processor to implement the method of the SCA service concurrency control device based on custom annotations as described above.

[0013] To achieve the above object, the present invention discloses a computer-readable storage medium having a program stored thereon, and when the program is executed by a processor, the method of the SCA service concurrency control device based on custom annotations as described above is implemented.

[0014] The present invention provides a custom annotation for tasks that need to perform concurrency control to identify and reference, then intercepts the corresponding tasks according to the custom annotation, and obtains the corresponding annotation parameters, so as to use Redis to add a distributed lock to the tasks according to the annotation parameters, and add the tasks to the task queue, and appropriately extend the valid time of the distributed lock of the uncompleted tasks by monitoring the valid time of the distributed locks of the tasks in the task queue, so as to effectively maintain the consistency and integrity of the SCA service data, and the concurrency control logic can be implemented efficiently and independently through the annotation method, reducing the intrusion into the business code to effectively improve the overall performance of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Figure 1 It is a flowchart of the SCA service concurrency control method based on custom annotations according to an embodiment of the present invention.

[0016] Figure 2 It is a module diagram of the SCA service concurrency control device based on custom annotations according to an embodiment of the present invention.

[0017] Figure 3 It is a system diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0018] To describe in detail the technical content, structural features, achieved objects and effects of the present invention, the following is described in detail in conjunction with the embodiments and with reference to the drawings.

[0019] Embodiment 1 Please refer to Figure 1 , the present invention discloses a method for SCA service concurrency control based on custom annotations. A custom annotation is created in the SCA service system, and the concurrency control method includes: It should be noted that before executing the concurrency control method, a new annotation @interface needs to be created in the SCA service system to define and form a custom annotation, and set related annotation parameters for the custom annotation for tasks that need to perform concurrency control to reference and mark.

[0020] 101. Intercept tasks marked with custom annotations and obtain the annotation parameters of the custom annotations; Using custom annotations to achieve centralized scanning and processing of the business that requires concurrent control can maximize the simplification of code logic and achieve efficient concurrent control without increasing the complexity of the SCA system.

[0021] Further, "intercept tasks marked with custom annotations and obtain the annotation parameters of the custom annotations" includes: 1011. Use an aspect interceptor to scan and intercept tasks marked with custom annotations; 1012. Register the intercepted tasks into the concurrent control container; 1013. Extract the annotation parameters of the custom annotations and the execution parameters of the tasks.

[0022] It can be understood that the above operations 1011 to 1013 are executed by using a custom core aspect interceptor. First, use the custom AOP pointcut to scan and intercept all tasks with this custom annotation added, then register the tasks into the control container through AOP aspect technology, and obtain the relevant annotation parameters and execution parameters of the tasks. The concurrent control logic is set in the control container and triggered during task execution and controlled according to the extracted annotation parameters and execution parameters, but not limited to this.

[0023] Encapsulate the concurrent control mechanism into an independent control container to form a general concurrent control tool, which is convenient to be introduced into different business systems. Only by introducing relevant dependencies and performing simple configurations can the concurrent control tool be quickly used, greatly improving the convenience and flexibility of use.

[0024] 102. Use Redis to add a distributed lock to the task according to the obtained annotation parameters and set an initial value for the effective time of the distributed lock; Further, the annotation parameters include: parameter identification subscript, number of retry attempts to obtain, lock type, and lock release time.

[0025] By setting custom annotations in combination with distributed locks, atomic protection of some shared data during the execution of concurrent threads can be achieved, avoiding race conditions in the access of shared resources, thereby effectively improving data consistency and stability.

[0026] It can be understood that the parameter identification subscript is used to identify the specific parameter positions that need to be locked in the task, so that the locking operation can be precise to specific business parameters; the number of retry acquisitions is used to set the number of times to retry acquiring the lock when the lock cannot be acquired; the lock type is used to indicate the type of lock that needs to be added for the current task, and different lock strategies for different business requirements can be implemented by setting custom locks; the lock release time is used to ensure that the lock resources are released in a timely manner to prevent deadlocks.

[0027] Furthermore, the distributed lock includes a custom lock, and the lock parameters of the custom lock include a task lock key, an effective duration, thread execution data, and the number of attempts.

[0028] Specifically, in this embodiment, custom locks are set in the SCA business system to meet the requirements of different services. When setting different custom annotations for different tasks, a specific custom lock can be specified. It can be understood that the task lock key is used to identify the task operation that needs to be locked currently, so that different business operations can achieve independent concurrent control; the effective duration is used to specify the effective duration of the lock to avoid long-term occupation of lock resources; the thread execution data is used to record the execution information of the current thread for subsequent tracking; the number of attempts is used to define the number of times the lock can be retried to acquire the lock before it is released.

[0029] It can be understood that before the task execution, the distributed lock mechanism is implemented through the Redis component, and a lock key corresponding to the distributed lock is generated to ensure that only one thread can execute the task at the same time, ensuring thread safety, effectively avoiding concurrent conflicts, and setting the initial value of the effective time of the distributed lock according to the effective duration in the lock parameters of the distributed lock. After the setting is completed, the effective time of the distributed lock starts counting down from the initial value, but this is not a limitation.

[0030] 103. Add the task with the distributed lock added to the task queue; 104. Monitor the effective time of the distributed lock of each task in the task queue, and extend the effective time of the distributed lock of the uncompleted tasks before the distributed lock becomes invalid; It can be understood that by setting a custom daemon thread to monitor tasks with a long execution time and perform corresponding timeout processing, in the case of task timeout, extend the effective time of the distributed lock to ensure that the task can be completed smoothly to the greatest extent and avoid data anomaly problems caused by the release of the distributed lock while the task has not been executed.

[0031] Furthermore, "monitor the effective time of the distributed lock of each task in the task queue" includes: 1041. Determine whether the effective time of the distributed lock of the task is zero. If it is zero, remove the task from the task queue; 1042. Determine whether the execution count of the task is greater than the execution retry count. If the determination is yes, remove the task from the task queue.

[0032] It can be understood that the custom daemon thread periodically scans the tasks in the task queue, filters out the completed and un-completable tasks through the effective time of the lock and the execution count of the task, and removes these tasks from the task queue to save the number of tasks monitored in each loop of the daemon thread, so as to improve the timeliness and effectiveness of the daemon thread monitoring.

[0033] Furthermore, "extending the effective time of the distributed lock of the un-completed task before the distributed lock becomes invalid" includes: 1043. Determine whether the effective time of the distributed lock of the task is less than one-third of the initial value of the effective time. If the determination is yes, increase the effective time of the distributed lock by a preset extension time.

[0034] It can be understood that most tasks can be completed within two-thirds of the effective duration of the distributed lock, but the execution time of some tasks is relatively long. Therefore, the daemon thread will screen out these tasks by comparing the effective time of the distributed lock with a set threshold (one-third of the initial value of the effective time), and appropriately extend the effective time of the distributed lock corresponding to the task to ensure that the distributed lock is not interrupted and the task is executed within the effective time of the distributed lock, which is beneficial to ensuring data consistency.

[0035] 105. Use Redis to release the distributed lock of the completed task.

[0036] It should be noted that after the task is completed, the distributed lock resource is released in a timely manner by deleting the lock key of the distributed lock generated when obtaining the distributed lock in Redis to ensure the stability and efficiency of the system.

[0037] Furthermore, after "using Redis to release the distributed lock of the completed task", it also includes: 106. Record the obtained annotation parameters, the added distributed lock, and the exceptions that occur during task execution in the log.

[0038] It can be understood that the error information during the execution of the concurrent control method is captured and recorded in real time by using the diary recording mechanism. The recorded error information includes the exception type, stack information, relevant business context, and the specific task that triggers the exception, which is beneficial to realizing the real-time monitoring of the system operation state, providing comprehensive data support for error troubleshooting and problem analysis during system maintenance and optimization, so that developers can quickly locate the root cause of the problem through the log information and optimize the system stability.

[0039] Embodiment 2 Please refer to Figure 1 and Figure 2 , the present invention discloses an SCA service concurrency control device based on custom annotations, which includes: An interception module 201, configured to intercept tasks marked with custom annotations and obtain annotation parameters of the custom annotations; A first increment module 202, configured to use Redis to add a distributed lock to the task according to the obtained annotation parameters and set an initial value for the valid time of the distributed lock; A second increment module 203, configured to add the task with the added distributed lock to the task queue; A monitoring module 204, configured to monitor the valid time of the distributed lock of each task in the task queue and extend the valid time of the distributed lock of the uncompleted task before the distributed lock becomes invalid; A release module 205, configured to release the distributed lock of the completed task by using Redis.

[0040] Embodiment Three Please refer to Figure 1 and Figure 3 , the present invention discloses an electronic device, which includes: One or more processors 301; One or more memories 302, configured to store one or more programs, and when the one or more programs are executed by the processor, the processor implements the SCA service concurrency control method based on custom annotations as described above.

[0041] Embodiment Four The embodiment of the present application discloses a computer-readable storage medium, on which a program is stored, and when the program is executed by a processor, the SCA service concurrency control method based on custom annotations as described above is implemented.

[0042] Embodiment Five The embodiment of the present application discloses a computer program product or a computer program, the computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. The processor of the electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the electronic device executes the SCA service concurrency control method based on custom annotations as described above.

[0043] It should be understood that in the embodiments of the present application, the so-called processor may be a central processing module (Central Processing Unit, CPU), and the processor may also be other general-purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), field-programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0044] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by hardware related to computer program instructions. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above methods. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory (Read-Only Memory, ROM) or a random access memory (Random Access Memory, RAM), etc.

[0045] The above-disclosed are only the preferred embodiments of the present invention. Of course, the scope of the rights of the present invention cannot be limited thereby. Therefore, equivalent changes made according to the scope of the patent application of the present invention still fall within the scope covered by the present invention.

Claims

1. A method for SCA service concurrent control based on custom annotations, characterized in that In the SCA service system, custom annotations are created. The concurrent control method includes: Intercept tasks marked with custom annotations and obtain the annotation parameters of the custom annotations; Use Redis to add a distributed lock to the task according to the obtained annotation parameters, and set an initial value for the valid time of the distributed lock; Add the task with the distributed lock added to the task queue; Monitor the valid time of the distributed lock of each task in the task queue, and extend the valid time of the distributed lock of the uncompleted tasks before the distributed lock becomes invalid; Use Redis to release the distributed lock of the completed tasks.

2. The SCA service concurrency control method based on custom annotation according to claim 1, wherein After "using Redis to release the distributed lock of the completed tasks", it further includes: Record the obtained annotation parameters, the addition of the distributed lock, and the abnormal situations during task execution to the log.

3. The SCA service concurrency control method based on custom annotation according to claim 1, characterized in that, The annotation parameters include: parameter identification subscript, number of retry acquisitions, lock type, and lock release time.

4. The SCA service concurrency control method based on custom annotation according to claim 1, characterized in that, The distributed lock includes a custom lock, and the lock parameters of the custom lock include task lock key, valid duration, thread execution data, and number of attempts.

5. The SCA service concurrency control method based on custom annotation according to claim 1, characterized in that "Intercept tasks marked with custom annotations and obtain the annotation parameters of the custom annotations" includes: Use an aspect interceptor to scan and intercept tasks marked with custom annotations; Register the intercepted tasks to the concurrent control container; Extract the annotation parameters of the custom annotations and the execution parameters of the tasks.

6. The SCA service concurrency control method based on custom annotation according to claim 1, characterized in that, "Monitor the valid time of the distributed lock of each task in the task queue" includes: Judge whether the valid time of the distributed lock of the task is zero. If it is zero, remove the task from the task queue; Judge whether the number of executions of the task is greater than the number of retry executions. If the judgment is yes, remove the task from the task queue.

7. The SCA service concurrency control method based on custom annotation according to claim 1, characterized in that, "Extend the valid time of the distributed lock of the uncompleted tasks before the distributed lock becomes invalid" includes: Judge whether the valid time of the distributed lock of the task is less than one-third of the initial value of the valid time. If the judgment is yes, increase the valid time of the distributed lock by a preset extension time.

8. An SCA service concurrency control device based on custom annotations, characterized in that, Includes: An interception module, used to intercept tasks marked with custom annotations and obtain the annotation parameters of the custom annotations; A first addition module, used to add a distributed lock to the task using Redis according to the obtained annotation parameters, and set an initial value for the valid time of the distributed lock; A second addition module, used to add the task with the distributed lock added to the task queue; A monitoring module, used to monitor the valid time of the distributed lock of each task in the task queue, and extend the valid time of the distributed lock of the uncompleted tasks before the distributed lock becomes invalid; A release module, used to release the distributed lock of the completed tasks using Redis.

9. An electronic device, characterized in that, Includes: One or more processors; One or more memories, used to store one or more programs. When one or more of the said programs are executed by the processor, the processor implements the SCA service concurrent control method based on custom annotations as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a program stored thereon, characterized in that, When the program is executed by the processor, it implements the SCA service concurrent control method based on custom annotations as described in any one of claims 1 to 7.