Business processing method and system, electronic equipment and storage medium

By identifying asynchronous tasks and persisting storage of execution records during asynchronous processing, the data inconsistency caused by machine downtime during asynchronous processing is solved, and the task re-execution is realized when service abnormality is achieved, improving the data consistency of business processing is achieved. performance and performance.

CN119105881APending Publication Date: 2024-12-10CHINA TELECOM ARTIFICIAL INTELLIGENCE TECHNOLOGY (BEIJING) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411110856.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-13
Publication Date
2024-12-10

AI Technical Summary

Technical Problem

During asynchronous processing, machine downtime causes the thread pool to be backlogged, resulting in inconsistent data between systems and business exceptions.

Method used

By receiving business processing requests, identifying asynchronous tasks, setting thread variables and updating memory queues, creating asynchronous execution records, and updating records during execution, determining whether the task is successful, re-executing the task when it fails, and using disk persistence to store records to ensure that Data consistency.

Benefits of technology

It improves system data consistency during business asynchronous processing, ensures that tasks can be actively re-execute, and business processing can be completed normally in service abnormalities, improving business processing performance in high-incidence scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119105881A_ABST
    Figure CN119105881A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a business processing method and system, electronic equipment and a storage medium, and belongs to the technical field of computers. According to the method, after a service processing request is received, an asynchronous task in the service processing request is identified, then a thread variable is set according to the asynchronous task, a memory queue is updated, and an asynchronous execution record of the asynchronous task is created in a disk, and the asynchronous execution record comprises the set thread variable and data cached in the memory queue. And calling an asynchronous execution method according to the set thread variable and the updated memory queue to asynchronously execute the asynchronous task, updating an asynchronous execution record of the asynchronous task in the process of executing the asynchronous task, judging whether the asynchronous task is successfully executed by the system, and when the asynchronous task is failed to execute, executing the asynchronous task. And if not, re-executing the asynchronous task according to the asynchronous execution record. According to the method and the device, the consistency of system data in a service asynchronous processing process can be improved, so that service processing is normally completed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a business processing method, system, electronic device and storage medium. Background Art

[0002] During the software development process, for complex business scenarios with data consistency, such as payment scenarios, one of the ways to optimize API interface performance is asynchronous processing, which is based on thread pools and mq message queues. When using thread pools to process business, multi-task parallel processing will reduce the response time of the API interface and ensure interface performance. However, if the machine suddenly crashes, the backlog of tasks in the thread pool in memory will be lost, resulting in inconsistent data between systems and ultimately business anomalies. Summary of the invention

[0003] The main purpose of the embodiments of the present application is to propose a business processing method, system, electronic device and storage medium, aiming to improve the consistency of system data during asynchronous business processing so as to normally complete business processing.

[0004] To achieve the above object, one aspect of an embodiment of the present application proposes a service processing method, comprising the following steps:

[0005] Receiving a business processing request and identifying an asynchronous task in the business processing request;

[0006] Setting thread variables according to the asynchronous task, updating a memory queue, and creating an asynchronous execution record of the asynchronous task in a disk, wherein the asynchronous execution record includes setting the thread variables and data cached in the memory queue;

[0007] Calling an asynchronous execution method according to the set thread variable and the updated memory queue to asynchronously execute the asynchronous task, and updating the asynchronous execution record of the asynchronous task during the execution of the asynchronous task;

[0008] Determine whether the asynchronous task is executed successfully;

[0009] When the asynchronous task fails to execute, the asynchronous task is re-executed according to the asynchronous execution record.

[0010] In some embodiments, receiving a business processing request and identifying an asynchronous task in the business processing request comprises the following steps:

[0011] Receive a business processing request and process the business processing request according to the main business process;

[0012] The asynchronous task of the business processing request in the process of the main business process is identified through the asynchronous annotation interceptor.

[0013] In some embodiments, setting thread variables according to the asynchronous task, updating the memory queue, and creating an asynchronous execution record of the asynchronous task in a disk comprises the following steps:

[0014] Determine task execution parameters, task execution class and method according to the asynchronous task;

[0015] Setting the thread variables according to the task execution parameters, and updating the memory queue according to the task execution class and method;

[0016] An asynchronous execution record of the asynchronous task is created in a disk according to the task execution parameters, the task execution class and the method, and the number of retries and the creation time of the asynchronous task are written into the asynchronous execution record.

[0017] In some embodiments, calling the asynchronous execution method according to the set thread variable and the updated memory queue to asynchronously execute the asynchronous task includes the following steps:

[0018] By calling the asynchronous task execution method, extracting the task execution parameters from the thread variables and extracting the task execution class and method from the memory queue;

[0019] Creating a target execution instance in a thread pool according to the extracted task execution parameters and the task execution class and method;

[0020] The target execution instance is executed by calling the child thread through the main thread in the thread pool to asynchronously execute the asynchronous task.

[0021] In some embodiments, updating the asynchronous execution record of the asynchronous task during the execution of the asynchronous task comprises the following steps:

[0022] Obtaining the execution progress of the target execution instance executed by the child thread;

[0023] The execution progress is updated in the asynchronous execution record of the asynchronous task.

[0024] In some embodiments, the service processing method further includes the following steps:

[0025] When the asynchronous task is executed successfully, the asynchronous execution record of the abnormal task in the disk is deleted.

[0026] In some embodiments, re-executing the asynchronous task according to the asynchronous execution record comprises the following steps:

[0027] Obtaining the asynchronous execution record of the asynchronous task stored in the disk, and updating the number of retries of the asynchronous execution record;

[0028] Determine whether the number of retries is less than an expected number;

[0029] When the number of retries is less than the expected number, the thread variable is set according to the asynchronous task, the memory queue is updated, and the asynchronous execution method is called according to the set thread variable and the updated memory queue to re-asynchronously execute the asynchronous task.

[0030] To achieve the above objective, another aspect of the embodiment of the present application provides a business processing system, including:

[0031] The first module is used to receive a business processing request and identify an asynchronous task in the business processing request;

[0032] A second module is used to set thread variables according to the asynchronous task, update the memory queue, and create an asynchronous execution record of the asynchronous task in the disk, wherein the asynchronous execution record includes setting the thread variables and the data cached in the memory queue;

[0033] A third module is used to call an asynchronous execution method according to the set thread variable and the updated memory queue to asynchronously execute the asynchronous task, and update the asynchronous execution record of the asynchronous task during the execution of the asynchronous task;

[0034] The fourth module is used to determine whether the asynchronous task is executed successfully. If the asynchronous task fails to execute, the asynchronous task is re-executed according to the asynchronous execution record.

[0035] To achieve the above-mentioned purpose, another aspect of an embodiment of the present application proposes an electronic device, which includes a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection and communication between the processor and the memory, and the program implements the method described in the above embodiment when executed by the processor.

[0036] To achieve the above-mentioned purpose, another aspect of an embodiment of the present application proposes a storage medium, which is a computer-readable storage medium used for computer-readable storage, and the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the method described in the above embodiment.

[0037] The business processing method, system, electronic device and storage medium proposed in the present application, after receiving a business processing request, identify the asynchronous task in the business processing request, then set the thread variable, update the memory queue and create an asynchronous execution record of the asynchronous task on the disk according to the asynchronous task, the asynchronous execution record includes setting the thread variable and the data cached in the memory queue, and then calling the asynchronous execution method according to the set thread variable and the updated memory queue to asynchronously execute the asynchronous task, and at the same time update the asynchronous execution record of the asynchronous task in the process of executing the asynchronous task, the system determines whether the asynchronous task is successfully executed, and when the asynchronous task fails to execute, the asynchronous task is re-executed according to the asynchronous execution record. The present application improves the business processing performance in high-incidence scenarios in an asynchronous manner, and persistently stores the task execution record on the disk. In the case of service abnormalities, it supports active re-execution of tasks based on the task execution record on the disk, thereby improving the consistency of system data during business asynchronous processing to complete business processing normally. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 is a flow chart of a business processing method provided by an embodiment of the present application;

[0039] Figure 2 yes Figure 1 Flow chart of step S101 in FIG.

[0040] Figure 3 yes Figure 1 Flow chart of step S102 in FIG.

[0041] Figure 4 yes Figure 1 Step S103 in the flowchart is a flowchart of calling the asynchronous execution method according to the set thread variable and the updated memory queue to asynchronously execute the asynchronous task steps;

[0042] Figure 5 yes Figure 1 A flowchart of the step of updating the asynchronous execution record of the asynchronous task during the execution of the asynchronous task in step S103;

[0043] Figure 6 yes Figure 1 Flow chart of step S105 in FIG.

[0044] Figure 7 It is a schematic diagram of the service request processing process provided by an embodiment of the present application;

[0045] Figure 8 This is a schematic diagram of an asynchronous task retry process provided by an embodiment of the present application;

[0046] Fig. 9 is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application;

[0047] Fig.10 It is a schematic diagram of a business processing system provided in an embodiment of the present application. DETAILED DESCRIPTION

[0048] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0049] It should be noted that, although the functional modules are divided in the system and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the system or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0050] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0051] First, some nouns involved in this application are analyzed:

[0052] Async Interceptor is a special interceptor used to process methods marked by @Async annotation and ensure that these methods are executed asynchronously. When these methods are called, the interceptor will capture these requests and ensure that the requests are executed asynchronously. This mechanism allows the application to not be blocked by waiting for long-running tasks when processing requests, thereby improving the responsiveness and performance of the system. Specifically, in the Spring framework, the implementation of asynchronous annotation interceptor depends on Spring's AOP (Aspect-Oriented Programming) mechanism and is implemented by proxy. Specifically, AnnotationAsyncExecutionInterceptor is the implementation class of MethodInterceptor. Its implementation of the invoke method of MethodInterceptor is completed in its parent class AsyncExecutionInterceptor, that is, when a method is marked by @Async annotation, it is actually intercepted and processed by the interceptor to ensure that the method is executed asynchronously.

[0053] The asynchronous task execution method is a method function that can realize asynchronous processing of tasks. Concurrent asynchronous tasks are processed by multiple threads by calling the asynchronous task execution method.

[0054] Thread pool is a commonly used technology in concurrent programming, which is used to manage and reuse threads to improve system performance and resource utilization. The thread pool includes a thread pool manager, a work queue, and a thread pool thread. The thread pool manager is responsible for the creation, destruction, and management of threads, as well as the status monitoring and scheduling of thread pool tasks. The work queue is used to store tasks to be executed. When the threads in the thread pool are all executing tasks, new tasks will be placed in the work queue and wait for execution. There are many types of work queues, such as ArrayBlockingQueue, LinkedBlockingQueue, SynchronousQueue, etc. The thread pool thread is the thread that actually executes the task. The threads in the thread pool will continuously take tasks from the work queue and execute them. After execution, they will return to the thread pool and wait for the next task assignment. The working principle of the thread pool is as follows:

[0055] Task submission: When a new task needs to be executed, it is submitted to the thread pool.

[0056] Thread allocation: The thread pool manager checks the thread status in the current thread pool. If there is an idle thread, it directly assigns the task to the idle thread for execution; if there is no idle thread, it tries to put the task into the work queue and wait.

[0057] Task execution: The thread takes the task from the work queue and executes it. After execution, the thread returns to the thread pool and waits for the next task assignment.

[0058] Thread pool adjustment: If the work queue is full and the number of threads in the thread pool is less than the maximum number of threads, the thread pool manager will create a new thread to execute the task. At the same time, the thread pool manager will dynamically adjust the size of the thread pool according to the execution of the task and the status of system resources.

[0059] The embodiments of the present application provide a business processing method, system, electronic device and storage medium, which are intended to improve the consistency of system data during asynchronous business processing to normally complete business processing.

[0060] The business processing method, system, electronic device and storage medium provided in the embodiments of the present application are specifically described through the following embodiments. First, the business processing method in the embodiments of the present application is described.

[0061] The business processing method provided in the embodiment of the present application relates to the field of computer technology. The business processing method provided in the embodiment of the present application can be applied to a terminal, can be applied to a server side, or can be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the business processing method, etc., but is not limited to the above forms.

[0062] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.

[0063] Figure 1 is an optional flowchart of the business processing method provided in the embodiment of the present application. Figure 1 The method may include but is not limited to steps S101 to S105.

[0064] Step S101, receiving a business processing request and identifying an asynchronous task in the business processing request;

[0065] Step S102, setting thread variables according to the asynchronous task, updating the memory queue, and creating an asynchronous execution record of the asynchronous task in the disk, wherein the asynchronous execution record includes setting thread variables and data cached in the memory queue;

[0066] Step S103, calling the asynchronous execution method according to the set thread variable and the updated memory queue to asynchronously execute the asynchronous task, and updating the asynchronous execution record of the asynchronous task during the execution of the asynchronous task;

[0067] Step S104, determining whether the asynchronous task is executed successfully;

[0068] Step S105: when the asynchronous task execution fails, the asynchronous task is re-executed according to the asynchronous execution record.

[0069] Steps S101 to S105 shown in the embodiment of the present application, after receiving a business processing request, identify the asynchronous task in the business processing request, then set the thread variable according to the asynchronous task, update the memory queue, and create an asynchronous execution record of the asynchronous task on the disk. The asynchronous execution record includes setting the thread variable and the data cached in the memory queue, and then calling the asynchronous execution method according to the set thread variable and the updated memory queue to asynchronously execute the asynchronous task. At the same time, the asynchronous execution record of the asynchronous task is updated during the execution of the asynchronous task. The system determines whether the asynchronous task is successfully executed. When the asynchronous task fails to execute, the asynchronous task is re-executed according to the asynchronous execution record. The embodiment of the present application improves the business processing performance in high-incidence scenarios in an asynchronous manner, and persistently stores the task execution record on the disk. In the case of service abnormalities, it supports active re-execution of tasks based on the asynchronous execution record on the disk, thereby improving the consistency of system data during business asynchronous processing to complete business processing normally.

[0070] In step S101 of some embodiments, a business processing request can be received through a global request interceptor, and then the business request is processed according to the corresponding business processing main process, wherein the processing flow of the business processing request may involve tasks that need to be processed asynchronously, and therefore, it is necessary to identify and intercept the asynchronous tasks therein for asynchronous processing. Exemplarily, the business processing request is an order processing request. After receiving the order processing request, the order is processed according to the order processing flow in the system. The order processing flow includes processes such as user order placement, user payment, order generation, order delivery, and merchant payment collection. In this process, merchant payment collection may be a high-concurrency task, and merchant payment collection can be annotated as an asynchronous task, so that in the process of processing the order processing request, the merchant payment collection task can be subsequently processed asynchronously to ensure data consistency during the merchant payment collection process.

[0071] See also Figure 2 In some embodiments, step S101 may include but is not limited to steps S201 to S202:

[0072] Step S201, receiving a business processing request, and processing the business processing request according to the business main process;

[0073] Step S202: Identify the asynchronous tasks of the business processing requests during the business main process processing by using the asynchronous annotation interceptor.

[0074] In this embodiment, a business processing request can be received through a global request interceptor, and then the business request is processed according to the corresponding business processing main process, wherein the processing flow of the business processing request may involve tasks that need to be processed asynchronously, and an asynchronous annotation interceptor is set in the system. During the main process of business processing, the asynchronous task is intercepted by the asynchronous annotation interceptor, and the asynchronous task execution method is called to process the task. Exemplarily, the business processing request is an order processing request. After receiving the order processing request, the order is processed according to the order processing flow in the system. The order processing flow includes processes such as user ordering, user payment, order generation, order delivery, and merchant collection. Among them, the merchant collection is annotated as an asynchronous task by the system using specific character annotations. During the execution of the main process, the asynchronous annotation interceptor recognizes the above-mentioned specific characters in real time to intercept the asynchronous task of the merchant collection, and then performs subsequent asynchronous processing on the merchant collection task to ensure the consistency of data during the merchant collection process.

[0075] In step S102 of some embodiments, after the asynchronous annotation interceptor intercepts the asynchronous task, the asynchronous annotation interceptor parses the asynchronous task to set the thread variable and update the memory queue so that the asynchronous task can be executed asynchronously. A thread variable (Thread-Local Variables) is a special variable whose value is independent for each thread accessing the variable, that is, each thread can modify its copy independently without affecting the value of the variable in other threads. Thread variables are generally used to ensure the consistency and isolation of data in a multi-threaded environment. Thread variables can be used to store information related to the current user session, such as user ID, permissions, etc. In complex applications, a large amount of context information (such as database connection) may need to be passed to multiple functions or methods, and the context information can also be written into the thread variable, and the value written into the thread variable is called a thread parameter. A memory queue (Queue) is a first-in, first-out (FIFO) data structure for storing element sequences in memory. A memory queue can be an interface that provides basic operations on queues, such as add, poll, peek, etc. Add the execution instance of the asynchronous task to the memory queue to facilitate the calling of the asynchronous task execution method and realize the parallel processing of multiple asynchronous tasks.

[0076] See also Figure 3 In some embodiments, step S102 may include but is not limited to steps S301 to S303:

[0077] Step S301, determining task execution parameters, task execution class and method according to the asynchronous task;

[0078] Step S302, setting thread variables according to task execution parameters, and updating memory queues according to task execution classes and methods;

[0079] Step S303: Create an asynchronous execution record of the asynchronous task in the disk according to the task execution parameters, the task execution class and the method, and write the number of retries and the creation time of the asynchronous task in the asynchronous execution record.

[0080] In this embodiment, the asynchronous annotation interceptor intercepts the asynchronous task, parses the asynchronous task to determine the task executor or task execution context, and determines the task execution class and method, then saves the task executor or task execution context in the thread variable, and saves the task execution class and method in the memory queue. The task executor is used to execute asynchronous tasks or concurrent tasks. Its main function is to submit the task to a thread pool for execution, thereby avoiding blocking when executing tasks in the main thread. Saving the task executor in the thread parameter ThreadLocal (i.e., thread variable) is equivalent to storing a reference to the task executor in ThreadLocal so that each thread can access its own task executor instance. In another embodiment, the thread variable can store context information or configuration related to task execution instead of directly storing the task executor itself. The context information can contain various information about the task, such as the priority of the task, the logger, or any task-specific data that needs to be accessed during thread execution. Furthermore, the relevant data of the asynchronous tasks saved in the thread variables and memory queues, namely the task execution parameters, task execution classes and methods, are persisted and saved on the disk to form an asynchronous execution record of the asynchronous tasks, and the number of retries and creation time of the asynchronous tasks are written in the asynchronous execution record. By persistently storing the relevant data of the asynchronous tasks on the disk, in the event of an abnormal system crash, the asynchronous tasks can continue to be processed based on the asynchronous execution records on the disk, thereby ensuring the consistency of data between systems.

[0081] In step S103 of some embodiments, after the global request interceptor determines that the thread variable, the memory queue and the disk all maintain the relevant configuration of the asynchronous task, the global request interceptor calls the asynchronous execution method so that the asynchronous execution method executes the asynchronous task based on the task execution parameters of the thread variable, the task execution class and method of the memory queue. The asynchronous execution method may be encapsulated as an atomic capability, allowing the program to continue to execute other tasks while waiting for a certain operation (such as I / O operation, database query, etc.) to be completed, thereby improving the execution efficiency and response speed of the program. The asynchronous execution method implementation method includes thread pool, timer, asynchronous scheduling, etc. In the process of executing the asynchronous task, the asynchronous execution record of the asynchronous task can be updated synchronously, specifically, the asynchronous execution method returns the task execution progress to the global request interceptor, and then the global request interceptor updates the task execution progress to the asynchronous execution record of the disk. In another embodiment, it can also be that the asynchronous execution method directly interacts with the disk, and the asynchronous execution method updates the task execution progress to the asynchronous execution record of the disk while processing the asynchronous task. By updating the task execution progress to the asynchronous execution record of the asynchronous task, after the system abnormally crashes and restarts, it can be determined based on the asynchronous execution record whether the asynchronous task has been completed. If not, the asynchronous task can be re-executed.

[0082] See also Figure 4 In some embodiments, the step of calling the asynchronous execution method according to the set thread variable and the updated memory queue in step S103 to asynchronously execute the asynchronous task may include but is not limited to steps S401 to S403:

[0083] Step S401, extracting task execution parameters from thread variables and extracting task execution classes and methods from memory queues by calling an asynchronous task execution method;

[0084] Step S402, creating a target execution instance in the thread pool according to the extracted task execution parameters and task execution class and method;

[0085] Step S403, calling the child thread to execute the target execution instance through the main thread in the thread pool to asynchronously execute the asynchronous task.

[0086] In this embodiment, the asynchronous task execution method can be implemented based on the thread pool. Specifically, the global request interceptor calls the asynchronous task execution method, and the asynchronous task execution method extracts the task execution parameters from the thread variable (ThreadLocal) and the task execution class and method from the memory queue (Queue). According to the extracted task execution parameters and the task execution class and method, a target execution instance is created in the thread pool by reflection. In Java programming, a reflection API method is provided to dynamically call any method of an object at runtime, even if this method is unknown at compile time. In the thread pool, the main thread calls one of the child threads to execute the target execution instance, thereby improving the processing efficiency of the task. The main thread calls the child thread in the thread pool for business processing. If the call is successful, the relevant data of the asynchronous task in the memory queue and thread parameters can be deleted, and a response success message is returned to the global request interceptor to ensure performance.

[0087] See also Figure 5 In some embodiments, the step of updating the asynchronous execution record of the asynchronous task during the execution of the asynchronous task in step S103 may include but is not limited to steps S501 to S502:

[0088] Step S501, obtaining the execution progress of the child thread executing the target execution instance;

[0089] Step S502: Update the execution progress to the asynchronous execution record of the asynchronous task.

[0090] In this embodiment, the target execution instance is executed in a child thread of the thread pool. After the target execution instance is completed, a task execution result will be returned. The execution progress can be determined based on the task execution result. For example, if the target execution instance outputs the task execution result, it indicates that the execution progress is task completion processing. If the target execution instance does not output the task execution result, it indicates that the execution progress is task incomplete processing. Specifically, the target execution instance can return the task execution result to the global request interceptor, and then the global request interceptor updates the task execution progress to the asynchronous execution record on the disk based on the task execution result. The method of the target execution instance can also be anchored, so that the target execution instance interacts directly with the disk, and the anchor execution result is updated to the asynchronous execution record on the disk when executing to the anchor position. The execution results of each anchor point together constitute the asynchronous execution record.

[0091] In step S104 of some embodiments, the target execution instance can return the task execution result to the asynchronous annotation interceptor. If the task execution result (such as the successful modification feedback of the account modification task) is received within the expected time, it indicates that the task has been completed in the child thread, and the asynchronous task is considered to be executed successfully. If the task execution result is not received within the expected time, it indicates that the task may not be executed due to reasons such as system downtime or thread pool scheduling failure, and the asynchronous task execution is considered to have failed. It is understandable that in order to prevent the same asynchronous task from being repeatedly executed, the expected time can be set long enough. For example, the preset time can be the time after the current system high concurrent access cycle. In another embodiment, it is also possible to determine whether the asynchronous task is successfully executed by monitoring whether the system is running normally. Specifically, if the system abnormal downtime is detected between the time when the asynchronous annotation interceptor calls the asynchronous execution method to submit the asynchronous task to the thread pool and the time before the task execution result is received, the asynchronous task execution can be considered to have failed.

[0092] In some embodiments, when a task execution result is received, indicating that the task has been completed in the child thread, the persistent asynchronous execution record of the abnormal task in the disk is deleted to reduce disk storage pressure and prevent subsequent repeated execution of successful asynchronous tasks.

[0093] In step S105 of some embodiments, when the asynchronous task fails to execute, the asynchronous task is re-executed according to the asynchronous execution record. Specifically, the system can read the asynchronous execution records in the time sequence of the asynchronous execution records in idle time, and re-execute the corresponding asynchronous task according to the read asynchronous task to ensure data consistency.

[0094] See also Figure 6 In some embodiments, step S105 may include but is not limited to steps S601 to S603:

[0095] Step S601, obtaining the asynchronous execution record of the asynchronous task stored in the disk, and updating the retry count of the asynchronous execution record;

[0096] Step S602, determining whether the number of retries is less than the expected number;

[0097] Step S603, when the number of retries is less than the expected number, the thread variable is set according to the asynchronous task, the memory queue is updated, and the asynchronous execution method is called according to the set thread variable and the updated memory queue to re-asynchronously execute the asynchronous task.

[0098] In this embodiment, after the system extracts the asynchronous execution record of the asynchronous task stored in the disk to re-execute the asynchronous task, it also updates the number of retries of the asynchronous execution record, that is, adds 1 to the number of retries, and then determines whether the number of retries of the asynchronous task is less than the expected number. If the number of retries is less than the expected number (such as 10 times), the thread variable is set according to the asynchronous task, the memory queue is updated, and the asynchronous execution method is called according to the set thread variable and the updated memory queue to re-asynchronously execute the asynchronous task. The specific asynchronous execution process is the same as the above embodiment, and this embodiment will not be repeated. If the number of retries is greater than or equal to the expected number, in order to reduce the system burden, the asynchronous task will not be re-executed. At this time, the global request interceptor can be fed back to give up executing the asynchronous task. In order to ensure the consistency of data between processes, the global request interceptor does not process the corresponding business processing request of the asynchronous task, and feeds back a request failure response to the client. For example, the business processing request is a transfer request, A transfers 1,000 yuan to B, and the global interception requester parses two tasks, task a is to reduce A's account by 1,000 yuan, and task b is to increase B's account by 1,000 yuan, where the modification operation of B's ​​account is annotated as an asynchronous task. The global interception requester completes task a in the main process and executes task b by calling the asynchronous task execution method. If the global request interceptor receives a message from the asynchronous task execution method that the execution of task b is abandoned, indicating that task b has not increased by 1,000 yuan, if task a has been executed, the execution operation is withdrawn. If task a has not been executed, a transfer failure message is fed back to the client to ensure data consistency.

[0099] Please refer to the following Figure 7 and Figure 8 The service request processing process and the asynchronous task retry process of the embodiment of the present application are described in detail. Before describing the details, Figure 7 and Figure 8The terms involved in the description are explained. Global Filter is a global request interceptor that intercepts global requests; AsynchronousExecutionInterceptor is an asynchronous annotation interceptor that intercepts annotation-marked methods and implements specific business logic; ThreadLocal<AsynchronousExecut i onRecordHo l der> It is a thread variable used for thread dimension data cache; Queue<AsynchronousExecut ionRecordBo> is a memory queue; InvokeBean is the target execution instance; threadPool is the thread pool; asynchronousExecut ionRecordDao is a persistent asynchronous execution record; targetClass method is the target class and method; dispatcher is a business processing request; doFiter is an interception operation; threadLoca l.set is a thread variable setting operation; queue.add is a memory queue addition operation; dao.save is a disk persistent storage operation; return is a feedback operation; executeRecord is an execution record operation; threadLoea l get is a thread variable read operation; queue.peek is a memory queue pop operation; create is a creation operation; queue.remove is a memory queue data removal operation; threadLoca l remove is a thread variable data removal operation; method invoke is a method call operation; do bus i ness is an instance execution operation; dao.de l is an asynchronous execution record deletion operation; do de l is a deletion execution operation; retryForJob represents a retry task; dao.page represents an asynchronous execution record paging query operation.

[0100] Please refer to Figure 7 , the service request processing process of the embodiment of the present application is described in detail as follows:

[0101] S11, the client calls the API interface, and Global Filter intercepts globally and executes the corresponding business, that is, the main business process is completed and the asynchronous tasks marked with asynchronous annotations are executed;

[0102] S12, the asynchronous annotation interceptor intercepts the asynchronous task, saves the task executor in the thread parameter ThreadLocal, saves the execution class and method in the memory queue Queue, persists the asynchronous execution record (including the execution target class and method, execution parameters, number of retries, creation time, etc.) on the disk, and returns it to the Global Filter.

[0103] S13, Globa l Filter calls the asynchronous task execution method to execute the above asynchronous task.

[0104] S14, the task execution method obtains the target executor from the thread parameter ThreadLocal, obtains the target execution class name and parameters from the memory queue Queue, and creates a target execution instance through reflection.

[0105] S16, the main thread calls the child thread in the thread pool to perform business processing. If the call is successful, the asynchronous task related data in the memory queue and thread parameters can be deleted, and a successful response is fed back to ensure performance.

[0106] S17, the child thread executes the actual asynchronous business (i.e., executes the target execution instance), and after the child thread executes successfully, the persistent asynchronous execution record is deleted at the same time. If the execution fails, the system logic is further kept consistent through the retry logic.

[0107] Please refer to Figure 8 , the asynchronous task retry process of the embodiment of the present application is described in detail as follows

[0108] S21, start executing the retry task, query the asynchronous execution records from the disk in paging order according to the time sequence, and re-asynchronously process them one by one.

[0109] S22, for each asynchronous execution record, save the corresponding task executor in the thread parameter ThreadLocal, and save the execution class and method in the memory queue Queue.

[0110] S23, calling the task execution method to obtain the target executor from the thread parameter ThreadLocal, obtain the target execution class name and parameters from the memory queue Queue, and create a target execution instance through reflection.

[0111] S24, the main thread calls the child thread in the thread pool to perform business processing. If the call is successful, the asynchronous task related data in the memory queue and thread parameters can be deleted, and a successful response is fed back to ensure performance.

[0112] S25, the child thread executes the actual asynchronous business (i.e., executes the target execution instance), and after the child thread executes successfully, the persistent asynchronous execution record is deleted at the same time. If the execution fails, the system logic is kept consistent through the retry logic.

[0113] According to some embodiments of the present application, the business processing method of the embodiment of the present application is described in combination with the scenario of high-concurrency transfer. In a high-concurrency virtual currency payment scenario, users transfer virtual currency to each other. Ten thousand accounts A1~A10000 transfer currency to account B at the same time. At this time, it is necessary to deduct the account balances of A1~A10000 at the same time, and increase the account balance of account B. In this high-concurrency scenario, modification operations are performed on account data persisted in the same disk. In order to ensure data accuracy, locking (optimistic lock or pessimistic lock) is required, but locking will affect the overall performance of the API interface. Therefore, this implementation adopts the business processing method of the embodiment of the present application for account operations that are modified simultaneously to ensure the ultimate consistency of API interface performance and business data. Ten thousand users A1~A10000 simultaneously initiate currency transfers to user B. Each main thread in the system deducts the account of user A and increases the account balance of account B. The business is intercepted and executed as an asynchronous task by the asynchronous annotation interceptor as follows Figure 7 The asynchronous execution process shown in the figure is used to implement the modification operation of account B. For the asynchronous task that failed the operation of account B, the following Figure 8 The retry logic shown in the figure performs retry compensation for failed tasks to ensure the eventual consistency of data.

[0114] See also Fig.10 The embodiment of the present application also provides a business processing system, including:

[0115] The first module is used to receive a business processing request and identify an asynchronous task in the business processing request;

[0116] The second module is used to set thread variables according to the asynchronous task, update the memory queue, and create an asynchronous execution record of the asynchronous task in the disk, wherein the asynchronous execution record includes setting thread variables and data cached in the memory queue;

[0117] The third module is used to call the asynchronous execution method according to the set thread variable and the updated memory queue to asynchronously execute the asynchronous task, and update the asynchronous execution record of the asynchronous task during the execution of the asynchronous task;

[0118] The fourth module is used to determine whether the asynchronous task is executed successfully. If the asynchronous task fails to execute, the asynchronous task is re-executed according to the asynchronous execution record.

[0119] It can be understood that the contents of the above-mentioned business processing method embodiments are applicable to the present system embodiments, the functions specifically implemented by the present system embodiments are the same as those of the above-mentioned business processing method embodiments, and the beneficial effects achieved are also the same as those achieved by the above-mentioned business processing method embodiments.

[0120] The embodiment of the present application also provides an electronic device, the electronic device comprising: a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection and communication between the processor and the memory, and the program is executed by the processor to realize the above-mentioned business processing method. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.

[0121] See also Fig. 9 , Fig. 9 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:

[0122] The processor 901 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;

[0123] The memory 902 may be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 902 may store an operating system and other application programs. When the technical solution provided in the embodiments of this specification is implemented by software or firmware, the relevant program code is stored in the memory 902, and the processor 901 calls and executes the service processing method of the embodiments of this application;

[0124] Input / output interface 903, used to implement information input and output;

[0125] Communication interface 904, used to realize communication interaction between the device and other devices, which can be realized through wired mode (such as USB, network cable, etc.) or wireless mode (such as mobile network, WI FI, Bluetooth, etc.);

[0126] A bus 905 that transmits information between various components of the device (e.g., the processor 901, the memory 902, the input / output interface 903, and the communication interface 904);

[0127] The processor 901 , the memory 902 , the input / output interface 903 and the communication interface 904 are connected to each other in communication within the device via a bus 905 .

[0128] An embodiment of the present application also provides a storage medium, which is a computer-readable storage medium used for computer-readable storage. The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the above-mentioned business processing method.

[0129] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0130] The business processing method, device, electronic device and storage medium provided by the embodiments of the present application, after receiving a business processing request, identify the asynchronous task in the business processing request, then set the thread variable, update the memory queue and create an asynchronous execution record of the asynchronous task in the disk according to the asynchronous task, the asynchronous execution record includes setting the thread variable and the data cached in the memory queue, and then calling the asynchronous execution method according to the set thread variable and the updated memory queue to asynchronously execute the asynchronous task, and at the same time update the asynchronous execution record of the asynchronous task in the process of executing the asynchronous task, the system determines whether the asynchronous task is successfully executed, and when the asynchronous task fails to execute, the asynchronous task is re-executed according to the asynchronous execution record. The embodiments of the present application improve the business processing performance in high-incidence scenarios in an asynchronous manner, and support active re-execution of tasks based on the asynchronous execution records in the disk in the case of service abnormalities through the asynchronous execution records stored persistently on the disk, thereby improving the consistency of system data during business asynchronous processing to complete business processing normally.

[0131] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0132] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.

[0133] The system embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.

[0134] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.

[0135] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0136] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0137] In the several embodiments provided in the present application, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of systems or units, which can be electrical, mechanical or other forms.

[0138] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0139] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0140] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.

[0141] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.

Claims

1. A business processing method, characterized in that: The following steps are involved: Receiving a business processing request and identifying an asynchronous task in the business processing request; Setting thread variables according to the asynchronous task, updating a memory queue, and creating an asynchronous execution record of the asynchronous task in a disk, wherein the asynchronous execution record includes setting the thread variables and data cached in the memory queue; Calling an asynchronous execution method according to the set thread variable and the updated memory queue to asynchronously execute the asynchronous task, and updating the asynchronous execution record of the asynchronous task during the execution of the asynchronous task; Determine whether the asynchronous task is executed successfully; When the asynchronous task fails to execute, the asynchronous task is re-executed according to the asynchronous execution record.

2. The service processing method according to claim 1, characterized in that: The receiving of the business processing request and identifying the asynchronous task in the business processing request includes the following steps: Receive a business processing request and process the business processing request according to the main business process; The asynchronous task of the business processing request in the process of the main business process is identified through the asynchronous annotation interceptor.

3. The service processing method according to claim 2, characterized in that: The step of setting thread variables according to the asynchronous task, updating the memory queue, and creating an asynchronous execution record of the asynchronous task in a disk comprises the following steps: Determine task execution parameters, task execution class and method according to the asynchronous task; Setting the thread variables according to the task execution parameters, and updating the memory queue according to the task execution class and method; An asynchronous execution record of the asynchronous task is created in a disk according to the task execution parameters, the task execution class and the method, and the number of retries and the creation time of the asynchronous task are written into the asynchronous execution record.

4. The service processing method according to claim 1, characterized in that: The step of calling the asynchronous execution method according to the set thread variable and the updated memory queue to asynchronously execute the asynchronous task comprises the following steps: By calling the asynchronous task execution method, extracting the task execution parameters from the thread variables and extracting the task execution class and method from the memory queue; Creating a target execution instance in a thread pool according to the extracted task execution parameters and the task execution class and method; The target execution instance is executed by calling the child thread through the main thread in the thread pool to asynchronously execute the asynchronous task.

5. The service processing method according to claim 4, characterized in that: The step of updating the asynchronous execution record of the asynchronous task during the execution of the asynchronous task comprises the following steps: Obtaining the execution progress of the target execution instance executed by the child thread; The execution progress is updated in the asynchronous execution record of the asynchronous task.

6. The service processing method according to claim 3, characterized in that: The business processing method further comprises the following steps: When the asynchronous task is executed successfully, the asynchronous execution record of the abnormal task in the disk is deleted.

7. The service processing method according to claim 1, characterized in that: The re-executing the asynchronous task according to the asynchronous execution record comprises the following steps: Obtaining the asynchronous execution record of the asynchronous task stored in the disk, and updating the number of retries of the asynchronous execution record; Determine whether the number of retries is less than an expected number; When the number of retries is less than the expected number, the thread variable is set according to the asynchronous task, the memory queue is updated, and the asynchronous execution method is called according to the set thread variable and the updated memory queue to re-asynchronously execute the asynchronous task.

8. A business processing system, characterized in that: include: The first module is used to receive a business processing request and identify an asynchronous task in the business processing request; A second module is used to set thread variables according to the asynchronous task, update the memory queue, and create an asynchronous execution record of the asynchronous task in the disk, wherein the asynchronous execution record includes setting the thread variables and the data cached in the memory queue; A third module is used to call an asynchronous execution method according to the set thread variable and the updated memory queue to asynchronously execute the asynchronous task, and update the asynchronous execution record of the asynchronous task during the execution of the asynchronous task; The fourth module is used to determine whether the asynchronous task is executed successfully. If the asynchronous task fails to execute, the asynchronous task is re-executed according to the asynchronous execution record.

9. An electronic device, characterized in that: The electronic device includes a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection and communication between the processor and the memory. When the program is executed by the processor, the steps of the method described in any one of claims 1 to 7 are realized.

10. A storage medium, the storage medium being a computer-readable storage medium, used for computer-readable storage, characterized in that: The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of any one of claims 1 to 7.