A closed-loop method and device for batch task processing
By customizing the pre- and post-listeners of tasks and steps in the Spring Batch framework, the closed-loop problem during the execution of batch tasks in the financial system is solved, and the determination of pre- and post-operations for tasks, steps, and data dimensions is realized. performance, improving the reliability and consistency of task execution.
Patent Information
- Application Number
- CN202411053485.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-02
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2044-08-02
AI Technical Summary
When the existing Spring Batch framework processes batch tasks in financial systems, it lacks pre- and post-listeners in the task dimension, step dimension, and data dimension, and cannot achieve a closed-loop task execution process, resulting in task execution in multi-process and fault-tolerant scenarios. uncertainty and data consistency issues.
In the Spring Batch framework, by customizing task pre- and post-listeners, perform task pre-operations, step pre-operations, data pre- and post-operations, and ensure the pre- and post-positioning of tasks, steps, and data dimensions. The determinism of the operation realizes the closed-loop batch task execution process.
Through custom listeners, preset operations are performed before and after batch task execution to ensure the integrity and consistency of tasks, steps and data, realizing a closed loop in all dimensions during batch task execution, and improving the reliability and accuracy of task execution. .
Smart Images

Figure CN118567822B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of batch task processing, and in particular to a closed-loop method and device for batch task processing. Background Art
[0002] In the financial system, batch tasks need to be executed to process the data and status of IOUs that change over time. In order to ensure the efficiency of batch task execution, various multi-process and multi-thread solutions need to be adopted to increase concurrency and accelerate execution. At the same time, as the amount of data increases, the number of data entries increases, the number of business scenarios increases, the complexity of business increases, and the cross-business and coupling increase, the possibility of abnormalities is also increasing, so it is also necessary to adopt various levels of fault-tolerant solutions to ensure the accuracy of batch task execution. On the basis of concurrency and fault-tolerant scenarios, in order to prevent unpredictable problems in the execution of batch tasks, it is necessary to ensure a closed loop in all dimensions. For example: a batch task needs to be locked before the task is executed and unlocked after the task is executed to ensure the uniqueness of task execution in distributed scenarios; a step of a batch task needs to insert prefabricated data before the step is executed, set the state to processing, and change the state to the final state after the step is executed to ensure the integrity of the state machine; a certain data of a certain step of a batch task needs to be marked before execution and unmarked after execution to ensure data consistency in concurrent scenarios.
[0003] In the prior art, the Spring Batch framework is used to process batch tasks. However, the pre-listeners and post-listeners of the task dimension and step dimension provided by the Spring Batch framework by default cannot meet the above-mentioned closed-loop requirements, and there is a lack of pre-listeners and post-listeners of the data dimension, so the closed loop of the data dimension cannot be realized.
[0004] Therefore, how to realize the closed loop of various dimensions in the batch task execution process based on the Spring Batch framework is an urgent problem to be solved. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a closed-loop method and device for batch task processing to achieve the purpose of closed-loop in various dimensions during the batch task execution process.
[0006] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:
[0007] A first aspect of an embodiment of the present invention discloses a closed-loop method for batch task processing, the method being applied to a financial system, and the method comprising:
[0008] In the Spring Batch framework, a batch task is created based on multiple IOU processing businesses generated by the financial system; the IOU processing business is used to process business data in the IOUs of the financial system; the batch task includes multiple processing steps, each of which processes one of the IOU processing businesses, and when each of the processing steps is executed, multiple threads are used to sequentially perform read operations, process operations, and write operations on the business data in the corresponding IOU processing business;
[0009] In response to the start instruction of the batch task, executing the batch task after executing a preset task pre-operation;
[0010] For each of the processing steps, executing a preset step pre-operation and starting to execute the processing step;
[0011] When the processing step is executed, before performing the read operation on any of the business data corresponding to the processing step, a preset data pre-operation is performed to obtain a pre-operation context, and the pre-operation context is stored in a thread variable of a target thread; the target thread is the thread processing the business data; the pre-operation context is used to characterize a preset data post-operation corresponding to the data pre-operation;
[0012] For each of the threads, after the write operation is performed on all the business data corresponding to the thread, each of the pre-operation contexts in the thread variable is traversed to perform the data post-operation corresponding to each of the pre-operation contexts;
[0013] When the data post-operation corresponding to each of the pre-operation contexts in all the thread variables is completed, executing the preset step post-operation;
[0014] When the post-step operations corresponding to all the processing steps are completed, the preset task post-step operations are executed.
[0015] Preferably, the method further comprises:
[0016] For each of the threads, detecting whether an exception occurs when the thread sequentially performs a read operation, a processing operation, and a write operation on any of the business data;
[0017] If so, the thread is interrupted, and each of the preceding operation contexts in the thread variable corresponding to the thread is traversed to execute the data post-operation corresponding to each preceding operation context.
[0018] Preferably, the detecting whether an abnormality occurs when the thread sequentially performs a reading operation, a processing operation, and a writing operation on any of the business data comprises:
[0019] By utilizing the exception handling block preset in the Spring Batch framework, when the thread sequentially performs a reading operation, a processing operation and a writing operation on any of the business data, the exception information is captured in real time, and when the exception information is captured, it is determined that an exception occurs.
[0020] Preferably, the method further comprises:
[0021] After any of the business data is read by the corresponding thread, the Spring Batch framework replaces the thread currently corresponding to the business data according to the thread reallocation mechanism, obtains the preceding operation context corresponding to the business data from the execution object of the business data, and stores the preceding operation context in the thread variable corresponding to the replaced thread.
[0022] Preferably, in response to the start instruction of the batch task, executing the batch task after executing a preset task pre-operation includes:
[0023] In response to the start instruction of the batch task, the task pre-operation execution component obtained by the user in advance through the custom task pre-listener in the Spring Batch framework is called to execute the batch task after executing the preset task pre-operation;
[0024] Correspondingly, when the post-step operations corresponding to all the processing steps are completed, the preset post-task operations are performed, including:
[0025] When the post-step operations corresponding to all the processing steps are executed, the post-task operation execution component obtained by the user in advance through the custom post-task listener in the SpringBatch framework is called to execute the preset post-task operation.
[0026] Preferably, for each of the processing steps, performing a preset step pre-operation and starting to execute the processing step includes:
[0027] For each of the processing steps, the step pre-operation execution component obtained by the user in advance through the custom step pre-listener in the Spring Batch framework is called to execute the preset step pre-operation and start executing the processing step;
[0028] Correspondingly, when the post-step operations corresponding to all the processing steps are completed, the preset post-task operations are performed, including:
[0029] When the post-step operations corresponding to all the processing steps are executed, the post-step operation execution component obtained by the user in advance through the custom post-step listener in the SpringBatch framework is called to execute the preset post-step operation.
[0030] A second aspect of an embodiment of the present invention discloses a closed-loop device for batch task processing, the device being applied to a financial system, and comprising:
[0031] A creation unit is used to create a batch task in a Spring Batch framework based on a plurality of IOU processing businesses generated by the financial system; the IOU processing business is used to process business data in the IOUs of the financial system; the batch task includes a plurality of processing steps, each of the processing steps corresponding to processing one of the IOU processing businesses, and when each of the processing steps is executed, a plurality of threads are used to sequentially perform a read operation, a processing operation, and a write operation on the business data in the corresponding IOU processing business;
[0032] A task pre-operation execution unit, configured to execute the batch tasks after executing a preset task pre-operation in response to a start instruction of the batch tasks;
[0033] A step pre-operation execution unit, used for executing a preset step pre-operation for each of the processing steps and starting to execute the processing step;
[0034] a data pre-operation execution unit, configured to, when the processing step is executed, before performing the read operation on any of the business data corresponding to the processing step, execute a preset data pre-operation to obtain a pre-operation context, and store the pre-operation context in a thread variable of a target thread; the target thread is the thread processing the business data; the pre-operation context is used to characterize a preset data post-operation corresponding to the data pre-operation;
[0035] A data post-operation execution unit, configured to, for each of the threads, after the write operation is performed on all the business data corresponding to the thread, traverse each of the pre-operation contexts in the thread variable and execute the data post-operation corresponding to each of the pre-operation contexts;
[0036] A post-step operation execution unit, configured to execute a preset post-step operation when the post-data operation corresponding to each of the preceding operation contexts in all the thread variables is completed;
[0037] The task post-operation execution unit is used to execute the preset task post-operation when the step post-operations corresponding to all the processing steps are completed.
[0038] Preferably, the device further comprises:
[0039] The exception handling unit is used to detect, for each of the threads, whether an exception occurs when the thread performs a read operation, a processing operation, and a write operation on any of the business data in sequence; if so, interrupt the thread, traverse each of the pre-operation contexts in the thread variable corresponding to the thread, and execute the data post-operation corresponding to each of the pre-operation contexts.
[0040] Preferably, the exception handling unit for detecting whether an exception occurs when the thread sequentially performs a read operation, a processing operation, and a write operation on any of the business data is specifically used to:
[0041] By utilizing the exception handling block preset in the Spring Batch framework, when the thread sequentially performs a reading operation, a processing operation and a writing operation on any of the business data, the exception information is captured in real time, and when the exception information is captured, it is determined that an exception occurs.
[0042] Preferably, the device further comprises:
[0043] A reallocation processing unit is used to obtain the preceding operation context corresponding to the business data from the execution object of the business data when the Spring Batch framework replaces the thread currently corresponding to the business data according to the thread reallocation mechanism after any of the business data is read by the corresponding thread, and store the preceding operation context in the thread variable corresponding to the replaced thread.
[0044] Based on the above-mentioned embodiment of the present invention, a closed-loop method and device for batch task processing are provided. In this solution, when the Spring Batch framework is used to process batch tasks in a multi-process and fault-tolerant scenario, a preset task pre-operation is performed before the batch task is executed, a preset step pre-operation is performed before the processing step is executed, a preset data pre-operation is performed before the business data is read, and a preset data post-operation is performed after the business data is written. After all data post-operations are executed, a preset step post-operation is performed. When the step post-operations corresponding to all processing steps are executed, the preset task post-operation is performed, thereby ensuring the certainty of the execution of the preset pre-operations and post-operations corresponding to the tasks, steps and data dimensions, so as to realize the closed loop of each dimension in the batch task execution process. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0046] Figure 1 A flow chart of a closed-loop method for batch task processing disclosed in an embodiment of the present invention;
[0047] Figure 2 This is an example diagram of a complete closed-loop process of batch task processing disclosed in an embodiment of the present invention;
[0048] Figure 3 A structural diagram of a closed-loop device for batch task processing disclosed in an embodiment of the present invention. DETAILED DESCRIPTION
[0049] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] In this application, the terms "comprises", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element.
[0051] As can be seen from the background technology, in the prior art, the Spring Batch framework is used to process batch tasks, but the pre-listeners and post-listeners of the task dimension and step dimension provided by the SpringBatch framework by default cannot meet the above-mentioned closed-loop requirements, and there is a lack of pre-listeners and post-listeners of the data dimension, so the closed loop of the data dimension cannot be realized.
[0052] Therefore, an embodiment of the present invention discloses a closed-loop method and device for batch task processing. In this solution, when using the Spring Batch framework to process batch tasks in a multi-process and fault-tolerant scenario, the certainty of the execution of pre-operations and post-operations preset corresponding to tasks, steps, and data dimensions is guaranteed to achieve a closed loop in each dimension during the batch task execution process.
[0053] like Figure 1 FIG. 1 is a flowchart of a closed-loop method for batch task processing disclosed in an embodiment of the present invention. The closed-loop method is applied to a financial system and includes the following steps:
[0054] Step S101: In the Spring Batch framework, batch tasks are created based on multiple IOU processing businesses generated by the financial system.
[0055] Among them, the IOU processing business is used to process the business data in the IOUs of the financial system.
[0056] It is understandable that in a financial system, batch tasks need to be executed during the day and at the end of the day to process multiple IOU processing businesses, and each IOU processing business is used to process business data of IOUs that change over time.
[0057] The process of Spring Batch framework processing batch tasks is as follows:
[0058] 1. Job definition: Define a batch task (Job), which usually consists of multiple steps (Step); batch task definition includes setting the name of the batch task, the order of steps, fault tolerance processing strategy and other information.
[0059] 2. Step configuration: Each batch job consists of one or more steps, which are the basic building blocks of batch jobs. Each step contains the configuration of one or more ItemReaders, ItemProcessors, and ItemWriters.
[0060] Among them, ItemReader is responsible for reading data, ItemProcessor is responsible for processing data, and ItemWriter is responsible for writing data.
[0061] Specifically, ItemReader (reader): responsible for reading data from a data source (such as a database, file, etc.), which can be a single read or a batch read, depending on the configuration; ItemProcessor (processor): processes and converts each piece of data read from the ItemReader. The processor is optional and can pass data without modifying it; ItemWriter (writer): responsible for writing the processed data to the target data source (such as a database, file, etc.), which can be a single write or a batch write, depending on the configuration.
[0062] 3. JobLauncher (batch task launcher): responsible for starting the execution of batch tasks. It can be triggered by command line, scheduled task or program call.
[0063] 4. JobRepository (batch task warehouse): stores metadata information about batch task execution, including the status of batch tasks, the status of steps, etc. Use the database to persist the running status of batch tasks to ensure the reliability and restartability of batch tasks.
[0064] 5. Listeners: Listeners can be used to monitor various events during the execution of batch tasks, such as before the batch task starts, after the batch task ends, before the step starts, after the step ends, etc. Listeners can be used for logging, statistical information collection, exception handling, etc.
[0065] 6. Transaction management: Spring Batch ensures data consistency and integrity of batch tasks through Spring's transaction management. Usually each step uses a transaction around it so that it can be rolled back or retried when an error occurs.
[0066] In general, the Spring Batch framework uses these components and mechanisms to process batch tasks of large-scale data, ensuring the controllability, reliability, and performance of its execution process.
[0067] In step S101, the batch task includes multiple processing steps, each processing step corresponds to processing one of the loan processing businesses. When each processing step is executed, multiple threads are used to perform read operations, processing operations and write operations on the business data in the corresponding loan processing business in sequence.
[0068] Among them, multiple business data corresponding to a processing step are assigned to each thread for multi-thread processing. Multi-thread processing refers to a technology that uses multiple threads (threads are the smallest unit that the operating system can schedule operations) to concurrently execute tasks (in the embodiment of the present invention, it refers to processing business data) in computer programming. Through multi-thread processing, the program can execute multiple business data at the same time, thereby improving the program's operating efficiency and resource utilization.
[0069] The reading operation, processing operation and writing operation are respectively implemented by the reader, processor and writer configured in the processing step.
[0070] In the specific implementation process of step S101, in the Spring Batch framework, a corresponding processing step is created for each loan processing business generated by the financial system, and a batch task is created based on each processing step, the execution order of each processing step set by the user, and the fault-tolerant processing strategy set by the user.
[0071] Step S102: in response to the start instruction of the batch task, the batch task is executed after performing a preset task pre-operation.
[0072] In step S102, the batch task start instruction may be triggered by a batch task starter.
[0073] Exemplarily, the preset task pre-operation may be task-level locking, pre-task status data pre-production, task pre-service pre-calling, and the like.
[0074] In the specific implementation process of step S102, in response to the batch task start instruction, the task pre-operation execution component obtained by the user in advance through the custom task pre-listener (beforeJob) in the Spring Batch framework is called to execute the batch task after executing the preset task pre-operation.
[0075] It should be noted that in Spring Batch, the pre-task listener is used to run some pre-processing logic before the batch task starts executing. It is usually used to initialize resources, set up context, or perform any operations that need to be completed before the batch task is actually executed.
[0076] The pre-listener of the task dimension in the prior art is already set by default, which does not meet the requirements of batch task processing in the financial system of this solution and cannot be called directly. The embodiment of the present invention customizes the task pre-listener according to actual business requirements, thereby solving the problem of the default task pre-listener not being compatible.
[0077] Step S103: For each processing step, perform a preset step pre-operation and start executing the processing step.
[0078] Exemplarily, the preset step pre-operation may be operations such as step-level locking, pre-step state data pre-production, and step pre-service pre-call.
[0079] In the specific implementation process of step S103, for each processing step, the step pre-operation execution component obtained by the user in advance through the custom step pre-listener (beforeStep) in the Spring Batch framework is called to execute the preset step pre-operation and start executing the processing step.
[0080] It should be noted that in Spring Batch, the pre-step listener is used to specify the method to be executed before the processing step is executed. It allows developers to perform some initialization or preparation before the processing step starts, such as initializing resources, setting context, or performing any operations that need to be completed before the processing step is executed.
[0081] The pre-listener of the step dimension in the prior art is already set by default, which does not meet the requirements of batch task processing in the financial system of this solution and cannot be called directly. The embodiment of the present invention customizes the pre-listener of the step according to actual business requirements, thereby solving the problem of the incompatibility of the default pre-listener of the step.
[0082] Step S104: when the processing step is executed, before performing a read operation on any business data corresponding to the processing step, a preset data pre-operation is performed to obtain a pre-operation context, and the pre-operation context is stored in a thread variable of the target thread.
[0083] In step S104, the preset data pre-operation may be data-level locking, data-level marking, data pre-status data pre-production, data pre-service pre-calling and other operations.
[0084] The pre-operation context refers to the input parameters, output parameters, process data and other information of the data pre-operation.
[0085] Assuming that the data pre-operation is data-level locking, the locked key, value, and result can be used as the pre-operation context.
[0086] For any business data, the target thread is the thread that processes the business data, that is, after executing the preset data pre-operation, the thread that continues to read, process and write the business data is the target thread.
[0087] It should be noted that thread variables (Threadlocal) mean that each thread has an independent copy of the variable. Even if it is the same static variable or global variable, different threads will have their own independent copies when accessing it. Thread variables are private variables of each thread, which can only be accessed and modified by the thread that created it, and are not affected by other threads.
[0088] It can be understood that the read operation can be to use the reader in the Spring Batch framework to read business data from the database of the financial system.
[0089] In one embodiment, due to the thread reallocation mechanism of the Spring Batch framework, during the process of processing business data, part of the business data after the read operation may be dynamically allocated to other threads to continue subsequent processing operations and write operations due to thread pool configuration or concurrent execution requirements.
[0090] Therefore, if the thread processing business data is replaced, it is necessary to reallocate the compatible operation for the business data, that is, to perform the pre-operation context obtained by performing the preset data pre-operation on the business data and store it back in the thread variable of the replaced thread.
[0091] More specifically, after any business data is read by the corresponding thread, the Spring Batch framework replaces the thread currently corresponding to the business data according to the thread reallocation mechanism, obtains the previous operation context corresponding to the business data from the execution object of the business data, and stores the previous operation context in the thread variable corresponding to the replaced thread.
[0092] The execution object may be an execution environment for executing preset data pre-operations.
[0093] Optionally, when any business data replacement thread continues to process, the preceding operation context corresponding to the business data is deleted from the thread variable of the thread before replacement.
[0094] Step S105: for each thread, after all business data corresponding to the thread are written, each pre-operation context in the thread variable is traversed, and the data post-operation corresponding to each pre-operation context is executed.
[0095] In step S105, the data post-operation corresponds to the preset data pre-operation, and the data post-operation corresponding to the data pre-operation can be accurately executed through the pre-operation context to achieve a closed loop of the data dimension.
[0096] Assuming that the data pre-operation is data-level locking, the corresponding data post-operation is data-level unlocking.
[0097] In the specific implementation, try-finally is used to ensure that when a write operation is performed on each business data corresponding to a thread, regardless of whether an exception occurs, all the preceding operation contexts in the ThreadLocal of the thread are traversed to perform post-data operations to ensure a closed loop.
[0098] Among them, if no exception occurs, after all business data corresponding to the thread are written, all pre-operation contexts in the ThreadLocal of the thread are traversed to perform post-data operations to ensure a closed loop.
[0099] If a business data write operation is abnormal, the remaining business data write operations are skipped, and all pre-operation contexts in the ThreadLocal of the thread are traversed to perform post-data operations to ensure a closed loop.
[0100] Try-finally is a structure used in programming to ensure that resources are released correctly, specifically including:
[0101] Try block: contains the logic for executing write operations on all business data corresponding to the thread.
[0102] finally block: used to define a code block that must be executed regardless of whether an exception occurs, that is, a code block that contains the logic of traversing all the pre-operation contexts in the ThreadLocal of the thread and performing post-data operations.
[0103] In one embodiment, for each thread, it is detected whether an exception occurs when the thread sequentially performs a read operation, a processing operation, and a write operation on any business data;
[0104] If so, the thread is interrupted, and each pre-operation context in the thread variable corresponding to the thread is traversed to execute the data post-operation corresponding to each pre-operation context.
[0105] In the embodiment of the present invention, the situation that the business data that has executed the preset data pre-operation cannot execute the data post-operation due to abnormal interruption in the business data processing is prevented from occurring.
[0106] Preferably, detecting whether an exception occurs when a thread sequentially performs a read operation, a processing operation, and a write operation on any business data includes:
[0107] By using the exception handling block preset in the Spring Batch framework, when the thread performs read operations, processing operations, and write operations on any business data in sequence, the exception information is captured in real time, and when the exception information is captured, it is determined that an exception has occurred.
[0108] Among them, try-catch can be used to capture exception information.
[0109] Try-catch is an exception handling structure used to capture and handle possible exceptions in a program. Specifically, the try-catch structure consists of two parts:
[0110] try block: Place code snippets that are expected to throw exceptions, such as the execution logic of a read operation.
[0111] Catch block: used to catch exceptions of a specified type and handle them accordingly. When the code in the try block throws an exception, the program will jump to the corresponding catch block for processing.
[0112] In the embodiment of the present solution, the catch block includes an interrupt thread, and traverses each pre-operation context in the thread variable corresponding to the thread, and executes the execution logic of the data post-operation corresponding to each pre-operation context.
[0113] The closed-loop method of the data dimension described in the above-mentioned embodiment of the present invention solves multiple scenario problems that hinder the realization of data-level closed-loop, including: multi-threaded execution of data, merged database transaction submission, exception and configuration fault tolerance, and thread replacement in the data processing process.
[0114] Step S106: When the data post-operation corresponding to each pre-operation context in all thread variables is completed, the preset step post-operation is performed.
[0115] In step S106, the preset post-step operation needs to correspond to the pre-step operation. For example, the pre-step operation: step-level locking, pre-step status data prefabrication, pre-step service pre-call corresponding post-step operations are: step-level unlocking, post-step status data conversion to final state, post-step service callback.
[0116] In the specific implementation process of step S106, when the post-step operations corresponding to all processing steps are executed, the post-step operation execution component obtained by the user in advance through the customized post-step listener (afterStep) in the Spring Batch framework is called to execute the preset post-step operation.
[0117] It should be noted that afterStep is a convenient mechanism provided by the Spring Batch framework to mark a method that will be automatically called after each processing step is completed.
[0118] The post-listener of the step dimension in the prior art is already set by default, which does not meet the requirements of batch task processing in the financial system of this solution and cannot be called directly. The embodiment of the present invention customizes the post-listener of the step according to actual business requirements, thereby solving the problem of the incompatibility of the default post-listener of the step.
[0119] Step S107: When the post-step operations corresponding to all processing steps are completed, the preset task post-step operations are executed.
[0120] In step S107, the preset post-task operation needs to correspond to the pre-task operation. For example, the pre-task operation includes task-level locking, pre-task status data prefabrication, and pre-task service pre-call. The corresponding post-task operations are: task-level unlocking, post-task status data conversion to final state, and post-task service callback.
[0121] In the specific implementation process of step S107, when the post-step operations corresponding to all the processing steps are executed, the post-task operation execution component obtained by the user in advance through the customized post-task listener (afterJob) in the Spring Batch framework is called to execute the preset post-task operation.
[0122] It should be noted that the post-task listener in the Spring Batch framework is used to generate specific operations or logic to be executed after the batch tasks are completed.
[0123] The post-listener of the task dimension in the prior art is already set by default, which does not meet the requirements of batch task processing in the financial system of this solution and cannot be called directly. The embodiment of the present invention customizes the task post-listener according to actual business requirements, thereby solving the problem of the default task post-listener not being compatible.
[0124] Based on the closed-loop method for batch task processing disclosed in the above embodiment of the present invention, Figure 2 , which is an example diagram of a complete closed-loop process of batch task processing disclosed in an embodiment of the present invention.
[0125] Among them, data 1 to data 15 represent the business data that can be processed simultaneously by threads A to E. For the data other than data 1 to data 15 in processing step Step 1, after data 1 to data 15 are processed, threads A to E continue to process them. In other words, the threads will be used cyclically, and after executing the read-process-write of one set of business data, they will execute the next set.
[0126] beforeJob represents the pre-task operation corresponding to the batch task Job, and afterJob represents the post-task operation corresponding to the batch task Job.
[0127] The batch task Job contains step Step1 and step Step2; beforeStep1 and beforeStep2 represent the pre-step operations corresponding to step Step1 and step Step2 respectively; afterStep1 and afterStep2 represent the post-step operations corresponding to step Step1 and step Step2 respectively.
[0128] It should be noted that the specific closed-loop process has been described in detail in the embodiments of the closed-loop method above, and reference may be made to each other, and will not be repeated here.
[0129] Based on the closed-loop method for batch task processing disclosed in the above-mentioned embodiment of the present invention, in this solution, when using the Spring Batch framework to process batch tasks in a multi-process and fault-tolerant scenario, the certainty of the execution of the pre-operations and post-operations preset corresponding to the tasks, steps and data dimensions is guaranteed to achieve a closed loop in each dimension during the batch task execution process.
[0130] Corresponding to the closed-loop method for batch task processing disclosed in the above embodiment of the present invention, as Figure 3 As shown, it is a structural diagram of a closed-loop device for batch task processing disclosed in an embodiment of the present invention. The device is applied to a financial system and includes: a creation unit 301, a task pre-operation execution unit 302, a step pre-operation execution unit 303, a data pre-operation execution unit 304, a data post-operation execution unit 305, a step post-operation execution unit 306 and a task post-operation execution unit 307.
[0131] The creation unit 301 is used to create a batch task based on multiple loan processing businesses generated by the financial system in the Spring Batch framework; the loan processing business is used to process the business data in the loan of the financial system; the batch task includes multiple processing steps, each processing step corresponds to processing one of the loan processing businesses, and when each processing step is executed, multiple threads are used to sequentially perform read operations, processing operations and write operations on the business data in the corresponding loan processing business;
[0132] The task pre-operation execution unit 302 is used to respond to the start instruction of the batch task and execute the batch task after executing the preset task pre-operation;
[0133] A step pre-operation execution unit 303, for executing a preset step pre-operation for each processing step and starting to execute the processing step;
[0134] The data pre-operation execution unit 304 is used to execute a preset data pre-operation before performing a read operation on any business data corresponding to the processing step when the processing step is executed, obtain a pre-operation context, and store the pre-operation context in a thread variable of a target thread; the target thread is a thread that processes business data; the pre-operation context is used to represent a data post-operation preset corresponding to the data pre-operation;
[0135] The data post-operation execution unit 305 is used for traversing each pre-operation context in the thread variable and executing the data post-operation corresponding to each pre-operation context after executing the write operation on all the business data corresponding to the thread for each thread;
[0136] A step post-operation execution unit 306 is used to execute a preset step post-operation when the data post-operation corresponding to each pre-operation context in all thread variables is completed;
[0137] The task post-operation execution unit 307 is used to execute the preset task post-operation when the post-step operations corresponding to all processing steps are completed.
[0138] Preferably, the closed-loop device further comprises:
[0139] The exception handling unit is used to detect, for each thread, whether an exception occurs when the thread performs read operations, processing operations and write operations on any business data in sequence; if so, the thread is interrupted, and each pre-operation context in the thread variable corresponding to the thread is traversed to execute the data post-operation corresponding to each pre-operation context.
[0140] Preferably, the exception handling unit for detecting whether an exception occurs when a thread sequentially performs a read operation, a processing operation, and a write operation on any business data is specifically used to:
[0141] By using the exception handling block preset in the Spring Batch framework, when the thread performs read operations, processing operations, and write operations on any business data in sequence, the exception information is captured in real time, and when the exception information is captured, it is determined that an exception has occurred.
[0142] Preferably, the closed-loop device also includes: a reallocation processing unit, which is used for obtaining the preceding operation context corresponding to the business data from the execution object of the business data when the Spring Batch framework replaces the thread currently corresponding to the business data according to the thread reallocation mechanism after any business data is read by the corresponding thread, and storing the preceding operation context in the thread variable corresponding to the replaced thread.
[0143] Preferably, the task pre-operation execution unit 302 is specifically used for:
[0144] In response to the start instruction of the batch task, the task pre-operation execution component obtained by the user in advance through the custom task pre-listener in the Spring Batch framework is called to execute the batch task after executing the preset task pre-operation;
[0145] Accordingly, the post-task operation execution unit 307 is specifically used for:
[0146] When the post-step operations corresponding to all processing steps are executed, the post-task operation execution component obtained by the user in advance through the custom post-task listener in the Spring Batch framework is called to execute the preset post-task operation.
[0147] Preferably, the step pre-operation execution unit 303 is specifically used to:
[0148] For each processing step, the pre-step operation execution component obtained by the user through the custom pre-step listener in the Spring Batch framework is called to execute the preset pre-step operation and start executing the processing step;
[0149] Accordingly, the post-step operation execution unit 306 is specifically used to:
[0150] When the post-step operations corresponding to all processing steps are executed, the post-step operation execution component obtained by the user in advance through the custom post-step listener in the Spring Batch framework is called to execute the preset post-step operation.
[0151] Based on a closed-loop device for batch task processing disclosed in the above-mentioned embodiment of the present invention, based on a closed-loop method for batch task processing disclosed in the above-mentioned embodiment of the present invention, in this solution, when using the Spring Batch framework to process batch tasks in a multi-process and fault-tolerant scenario, the certainty of the execution of pre-operations and post-operations preset corresponding to tasks, steps and data dimensions is guaranteed to achieve a closed loop in each dimension during the batch task execution process.
[0152] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.
[0153] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0154] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A closed-loop method for batch task processing, It is characterized in that The method is applied to a financial system, and comprises: In the Spring Batch framework, a batch task is created based on multiple IOU processing businesses generated by the financial system; the IOU processing business is used to process business data in the IOUs of the financial system; the batch task includes multiple processing steps, each of which processes one of the IOU processing businesses, and when each of the processing steps is executed, multiple threads are used to sequentially perform read operations, process operations, and write operations on the business data in the corresponding IOU processing business; In response to the start instruction of the batch task, executing the batch task after executing a preset task pre-operation; For each of the processing steps, executing a preset step pre-operation and starting to execute the processing step; When the processing step is executed, before performing the read operation on any of the business data corresponding to the processing step, a preset data pre-operation is performed to obtain a pre-operation context, and the pre-operation context is stored in a thread variable of a target thread; the target thread is the thread processing the business data; the pre-operation context is used to characterize a preset data post-operation corresponding to the data pre-operation; For each of the threads, after the write operation is performed on all the business data corresponding to the thread, each of the pre-operation contexts in the thread variable is traversed to perform the data post-operation corresponding to each of the pre-operation contexts; When the data post-operation corresponding to each of the pre-operation contexts in all the thread variables is completed, executing the preset step post-operation; When the step post-operations corresponding to all the processing steps are completed, the preset task post-operations are executed.
2. The method according to claim 1, It is characterized in that The method further comprises: For each of the threads, detecting whether an exception occurs when the thread sequentially performs a read operation, a processing operation, and a write operation on any of the business data; If so, the thread is interrupted, and each of the preceding operation contexts in the thread variable corresponding to the thread is traversed to execute the data post-operation corresponding to each preceding operation context.
3. The method according to claim 2, It is characterized in that The detecting whether an exception occurs when the thread sequentially performs a read operation, a processing operation, and a write operation on any of the business data includes: By utilizing the exception handling block preset in the Spring Batch framework, when the thread sequentially performs a reading operation, a processing operation and a writing operation on any of the business data, the exception information is captured in real time, and when the exception information is captured, it is determined that an exception occurs.
4. The method according to claim 1, It is characterized in that The method further comprises: After any of the business data is read by the corresponding thread, the Spring Batch framework replaces the thread currently corresponding to the business data according to the thread reallocation mechanism, obtains the preceding operation context corresponding to the business data from the execution object of the business data, and stores the preceding operation context in the thread variable corresponding to the replaced thread.
5. The method according to claim 1, It is characterized in that The step of executing the batch tasks after executing a preset task pre-operation in response to the start instruction of the batch tasks includes: In response to the start instruction of the batch task, the task pre-operation execution component obtained by the user in advance through the custom task pre-listener in the Spring Batch framework is called to execute the batch task after executing the preset task pre-operation; Correspondingly, when the post-step operations corresponding to all the processing steps are completed, the preset post-task operations are performed, including: When the post-step operations corresponding to all the processing steps are executed, the post-task operation execution component obtained by the user in advance through the custom post-task listener in the Spring Batch framework is called to execute the preset post-task operation.
6. The method according to any one of claims 1 to 5, It is characterized in that For each of the processing steps, performing a preset step pre-operation and starting to execute the processing step includes: For each of the processing steps, the step pre-operation execution component obtained by the user in advance through the custom step pre-listener in the Spring Batch framework is called to execute the preset step pre-operation and start executing the processing step; Correspondingly, when the post-step operations corresponding to all the processing steps are completed, the preset post-task operations are performed, including: When the post-step operations corresponding to all the processing steps are executed, the post-step operation execution component obtained by the user in advance through the custom post-step listener in the Spring Batch framework is called to execute the preset post-step operation.
7. A closed-loop device for batch task processing, It is characterized in that The device is applied to a financial system, and comprises: A creation unit is used to create a batch task in a Spring Batch framework based on a plurality of IOU processing businesses generated by the financial system; the IOU processing business is used to process business data in the IOUs of the financial system; the batch task includes a plurality of processing steps, each of the processing steps corresponding to processing one of the IOU processing businesses, and when each of the processing steps is executed, a plurality of threads are used to sequentially perform a read operation, a processing operation, and a write operation on the business data in the corresponding IOU processing business; A task pre-operation execution unit, configured to execute the batch tasks after executing a preset task pre-operation in response to a start instruction of the batch tasks; A step pre-operation execution unit, used for executing a preset step pre-operation for each of the processing steps and starting to execute the processing step; a data pre-operation execution unit, configured to, when the processing step is executed, before performing the read operation on any of the business data corresponding to the processing step, execute a preset data pre-operation to obtain a pre-operation context, and store the pre-operation context in a thread variable of a target thread; the target thread is the thread processing the business data; the pre-operation context is used to characterize a preset data post-operation corresponding to the data pre-operation; A data post-operation execution unit, configured to, for each of the threads, after the write operation is performed on all the business data corresponding to the thread, traverse each of the pre-operation contexts in the thread variable and execute the data post-operation corresponding to each of the pre-operation contexts; A post-step operation execution unit, configured to execute a preset post-step operation when the post-data operation corresponding to each of the preceding operation contexts in all the thread variables is completed; The task post-operation execution unit is used to execute the preset task post-operation when the step post-operations corresponding to all the processing steps are completed.
8. The device according to claim 7, It is characterized in that The device also includes: The exception handling unit is used to detect, for each of the threads, whether an exception occurs when the thread performs a read operation, a processing operation, and a write operation on any of the business data in sequence; if so, interrupt the thread, traverse each of the pre-operation contexts in the thread variable corresponding to the thread, and execute the data post-operation corresponding to each of the pre-operation contexts.
9. The device according to claim 8, It is characterized in that The exception handling unit is used to detect whether an exception occurs when the thread sequentially performs a read operation, a processing operation, and a write operation on any of the business data, specifically for: By utilizing the exception handling block preset in the Spring Batch framework, when the thread sequentially performs a reading operation, a processing operation and a writing operation on any of the business data, the exception information is captured in real time, and when the exception information is captured, it is determined that an exception occurs.
10. The device according to claim 7, It is characterized in that The device also includes: A reallocation processing unit is used to obtain the preceding operation context corresponding to the business data from the execution object of the business data when the Spring Batch framework replaces the thread currently corresponding to the business data according to the thread reallocation mechanism after any of the business data is read by the corresponding thread, and store the preceding operation context in the thread variable corresponding to the replaced thread.
Citation Information
Patent Citations
Batch job execution method, device, equipment, medium and product
CN114240632A
Financial service batch processing method and device, computer equipment and storage medium
CN118014506A
Job management method, job management system, and job management program
JP2016018348A
Context switch data prefetching in multithreaded computer
US20050138627A1
Financial data interaction method, apparatus computer device and storage medium
WO2020006903A1
