Code dynamic loading execution method, actuator and system

The Groovy class loader loads and executes code after cache verification is passed, and solves the problem that new code cannot be loaded and executed dynamically in the existing technology, and realizes the system's dynamic adjustment and online real-time execution capabilities.

CN119690531APending Publication Date: 2025-03-25CHINA CONSTR BANK CORP SICHUAN BRANCH
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202311236654.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-09-22
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

The existing technology cannot dynamically load and execute new code, and cannot achieve online development and real-time operation.

Method used

By obtaining the code and task types to be executed, using the Groovy class loader to load the code after the cache verification is passed, constructing the Class object and creating a new instance, replacing the domain value of the old instance, and updating the Spring container bean factory.

Benefits of technology

It realizes dynamic loading and executing of code, so that the system can dynamically adjust business rules without stopping service, and supports real-time online execution of commands and code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119690531A_ABST
    Figure CN119690531A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of development assistance, in particular to a code dynamic loading execution method, an executor and a system. According to the code dynamic loading and execution method, dynamic loading and dynamic execution are achieved through a Grouping class loader, when the system is integrated with a system using a Spring framework, a loaded instance can be injected into an instance factory managed by Spring, and an existing instance is updated, so that the system in operation dynamically adjusts a business rule under the condition that service is not stopped, and the service efficiency is improved. And commands and codes can be executed online in real time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of development assistance technology, and in particular to a code dynamic loading execution method, an executor and a system. Background Art

[0002] As banking business develops and the market is deeply segmented, software systems need to be able to quickly respond to the ever-changing market in order to maintain their advantages in the fierce market competition. For business scenarios with flexible and changeable business rules, the existing model requires frequent iterative upgrades of the software system. Since banking business systems are numerous and complex, too frequent system upgrades lead to multiple versions crossing, which poses a challenge to existing process management and easily causes production problems.

[0003] Technical personnel fully communicate with business personnel to deeply understand business rules, and then perform technical processing and modeling on business rules to extract fixed and variable parts; in the process of project implementation, the variable parts are parameterized, and the system can meet different business needs by adjusting parameters. Parameter adjustment can be configured in local configuration files or databases according to the specific system implementation situation. After manually updating parameters, hot updates can be achieved by restarting the application or by the application system regularly scanning the configuration file or configuration library; for distributed systems, a unified configuration center is generally established, and the application system automatically updates parameters when it detects changes in the configuration center. However, adjusting parameters can meet the needs of business rule changes to a certain extent, but it is relatively limited. Moreover, it is not competent for the adjustment of complex business rules and rapidly changing new requirements.

[0004] For example, the patent number CN202210217423.3 is a distributed configuration center and a method for replacing its JAVA running instance. This solution configures the JAR package in the configuration center, and the application system periodically scans the JAR package in the configuration center. If an update is found, the dynamic loading mechanism provided by JDK is used to update the JAR and replace the CLASS instance with the newly generated instance, thereby realizing the hot update of JAVA. This solution mainly realizes the dynamic replacement of existing JAVA running instances, but cannot dynamically load and execute the newly added JAVA code, and cannot achieve online development and real-time operation. Summary of the invention

[0005] Therefore, the technical problem to be solved by the present invention is to overcome the problem in the prior art that newly added codes cannot be dynamically loaded and executed.

[0006] In order to solve the above technical problems, the present invention provides a method for dynamically loading and executing code, comprising:

[0007] Get the code to be executed and the task type;

[0008] When the task type is Spring mode, after the cache verification is passed, the code to be executed is loaded using the Groovy class loader, a Class object is constructed and a new instance is created, each domain value of the new instance is replaced with the domain value corresponding to the old instance, and the new instance with the updated domain value is used to update the Spring container Bean factory.

[0009] Preferably, when the task type is the Bean mode, the code to be executed is loaded using the Groovy class loader, a Class object is constructed and a new instance is created, and an interface method of the instance is called to implement task processing.

[0010] Preferably, when the task type is command mode, a subprocess is created to execute the task.

[0011] Preferably, the cache verification includes:

[0012] The MD5 value of the code to be executed is calculated and compared with the MD5 value of the code in the cache. If there is no identical MD5 value, it is determined that the code to be executed does not exist in the cache and the cache check passes. Otherwise, the cache check fails.

[0013] The present invention also provides a code dynamic loading executor, comprising:

[0014] The task information acquisition module is used to obtain the code to be executed and the task type;

[0015] The execution module, when the task type is Spring mode, is used to use the Groovy class loader to load the code to be executed after the cache verification passes, construct a Class object and create a new instance, replace the domain values ​​of the new instance with the domain values ​​corresponding to the old instance, and update the Spring container Bean factory with the new instance after the domain values ​​are updated.

[0016] The present invention also provides a code dynamic loading execution system, comprising:

[0017] A user interface, used to accept user instructions;

[0018] A management center, used for sending the user instruction to the target executor;

[0019] The code dynamic loading executor as mentioned above is used to execute tasks according to the user instructions and return the execution results and execution logs to the management center.

[0020] Preferably, the management center includes user management, and the user management includes role management, authority management and account management.

[0021] Preferably, the management center also includes log management, and the log management includes log viewing, log cleaning and log transmission.

[0022] Preferably, the management center also includes source code management, and the source code management includes the creation, viewing, modification and deletion of codes.

[0023] Preferably, the management center further includes executor management, and the executor management includes executor registration and executor scheduling.

[0024] The above technical solution of the present invention has the following advantages compared with the prior art:

[0025] The code dynamic loading and execution method described in the present invention realizes dynamic loading and dynamic execution through the Groovy class loader. When integrated with a system using the Spring framework, the loaded instance can be injected into the instance factory managed by Spring, and the existing instance can be updated, so that the running system can dynamically adjust the business rules without stopping the service, and commands and codes can be executed online in real time. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] In order to make the content of the present invention more clearly understood, the present invention is further described in detail below according to specific embodiments of the present invention in conjunction with the accompanying drawings, wherein:

[0027] Figure 1 A flowchart of a method for dynamically loading and executing a code provided by the present invention;

[0028] Figure 2 It is a code dynamic loading executor task processing flow chart provided by the present invention;

[0029] Figure 3 This is a general architecture diagram of a code dynamic loading system provided by the present invention;

[0030] Figure 4 It is a user management function schematic diagram;

[0031] Figure 5 It is a user login flow chart;

[0032] Figure 6 It is a log management flow chart;

[0033] Figure 7 It is a flowchart for adding, checking and modifying code in source code management;

[0034] Figure 8 It is a flowchart for deleting code in source code management;

[0035] Fig. 9 It is a registration management flow chart;

[0036] Fig.10 It is a task scheduling flow chart. DETAILED DESCRIPTION

[0037] The core of the present invention is to provide a code dynamic loading and execution method, executor and system, which realize dynamic loading and dynamic execution, so that the running system can dynamically adjust business rules without stopping service, and can execute commands and codes online in real time.

[0038] In order to enable those skilled in the art to better understand the scheme of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0039] Please refer to Figure 1 , Figure 1 The following is a flowchart of a method for dynamically loading and executing a code provided by the present invention; the specific operation steps are as follows:

[0040] S101: Obtain the code to be executed and the task type;

[0041] S102: When the task type is Spring mode, after the cache check is passed, the code to be executed is loaded using the Groovy class loader, a Class object is constructed and a new instance is created, each domain value of the new instance is replaced with the domain value corresponding to the old instance, and the Spring container Bean factory is updated using the new instance after the domain value is updated.

[0042] The cache verification includes:

[0043] The MD5 value of the code to be executed is calculated and compared with the MD5 value of the code in the cache. If there is no identical MD5 value, it is determined that the code to be executed does not exist in the cache and the cache check passes. Otherwise, the cache check fails. The present invention uses the Groovy class loader to implement dynamic loading. A cache is designed to store the source code MD5. The MD5 value of the source code is calculated before each loading to determine whether it already exists in the cache, which effectively avoids repeated loading.

[0044] The code dynamic loading and execution method described in the present invention realizes dynamic loading and dynamic execution through the Groovy class loader. When integrated with a system using the Spring framework, the loaded instance can be injected into the instance factory managed by Spring, and the existing instance can be updated, so that the running system can dynamically adjust the business rules without stopping the service, and commands and codes can be executed online in real time.

[0045] like Figure 2 As shown, based on the above embodiments, this embodiment describes step S102 in detail:

[0046] When the task type is the Bean mode, the Groovy class loader is used to load the code to be executed, construct a Class object and create a new instance, and call the interface method of the instance to implement task processing.

[0047] When the task type is command mode, a subprocess is created to execute the task.

[0048] The present invention also provides a code dynamic loading executor; specifically, it may include:

[0049] The task information acquisition module is used to obtain the code to be executed and the task type;

[0050] The execution module, when the task type is Spring mode, is used to use the Groovy class loader to load the code to be executed after the cache verification passes, construct a Class object and create a new instance, replace the domain values ​​of the new instance with the domain values ​​corresponding to the old instance, and update the Spring container Bean factory with the new instance after the domain values ​​are updated.

[0051] The code dynamic loading executor of this embodiment is used to implement the aforementioned code dynamic loading execution method. Therefore, the specific implementation method of the code dynamic loading executor can be seen in the implementation method part of the aforementioned code dynamic loading execution method. For example, the task information acquisition module and the execution module are respectively used to implement steps S101 and S102 in the aforementioned code dynamic loading execution method. Therefore, its specific implementation method can refer to the description of the corresponding embodiments of each part, which will not be repeated here.

[0052] like Figure 3 As shown, the present invention also provides a code dynamic loading execution system; specifically, it may include:

[0053] The user interface is used to accept user instructions; the WebUI is an interface for user operations, through which users can manage users, view execution logs, edit and view codes, manage executors, etc.

[0054] The management center is used to send the user instructions to the target executor; the management center is the core part of the entire invention, including user management, executor management, log management and source code management. User management is used to manage the operating users of this tool and configure the user's role permissions; executor management manages the executors that have successfully registered with the management center by cluster grouping and dynamically tracks the health of each executor; log management centrally manages the logs generated during user operations and executor operation for easy viewing by users; source code management is used to store the code for user online programming and maintain multiple versions.

[0055] As mentioned above, the code dynamically loads the executor, which is used to execute tasks according to the user's instructions and return the execution results and execution logs to the management center; the executor is the agent of the management center. When the management center receives the user's instructions, it will distribute them to the corresponding executor for execution.

[0056] Based on the above embodiments, this embodiment describes the user management of the management center in detail:

[0057] like Figure 4 As shown, this module consists of three parts: role management, permission management and account management.

[0058] Role management: This tool supports three roles by default: administrator, advanced user and ordinary user. Only administrators can manage users. After the administrator successfully logs in, he can create new roles as needed and configure certain permissions. When creating a new role, you can choose to copy from the default role and then modify it. The three default roles of the system cannot be changed.

[0059] Permission management: Permissions are the operational capabilities of one or more executors (machine clusters), such as online code editing, publishing or running code, etc. Administrators can create new permissions and configure the operational capabilities of the executors; they can also modify and delete existing permissions.

[0060] Account management: The account management module includes account management and user login management. Administrators can create new accounts through account management, and modify, delete, deactivate, and activate existing accounts. The process of creating an account requires configuring roles and a list of available executors. Figure 5 As shown, the user login process will verify the legitimacy of the login account and display the corresponding function interface according to the pre-configured permissions.

[0061] like Figure 6 As shown, based on the above embodiments, this embodiment describes the log management of the management center in detail:

[0062] The logs generated by users when using this tool will be collected in the management center. Log management provides a unified entry to manage logs. The logs generated during the execution of tasks distributed by the management center to the executors are synchronized back to the management center and provided to users by the log management module. Abnormal logs containing keywords are highlighted to remind users to pay special attention. Keywords can be configured globally.

[0063] This module supports viewing logs by multiple dimensions such as executors, users, and tasks, and supports filtering logs with complex filtering conditions to meet the diverse needs of users. This module provides a log cleaning function that supports manual and automatic cleaning. Advanced users can configure the cleaning strategy and cleaning mechanism through the interface, and the system will automatically clean up according to the configuration.

[0064] This module provides external log transmission function, which can be easily integrated with other systems, such as transmitting log data to the monitoring center to realize health monitoring of this system.

[0065] like Figure 7 and Figure 8 As shown, based on the above embodiments, this embodiment describes the source code management of the management center in detail:

[0066] This module provides users with an online coding interface. After the user completes online development, the code can be published to the test sandbox for testing. It supports multi-version management of source code. Users can select historical versions to view or modify. After the new or modified historical version of the code is published, it can be entered into the version library after being reviewed and approved by senior users.

[0067] like Fig. 9 and Fig.10 As shown, based on the above embodiments, this embodiment describes the actuator management of the management center in detail:

[0068] Executor registration: During the startup process of the executor, the registration API of the management center will be called to register with the registration center. The registration request message contains the cluster name, machine IP address and service port of the executor. After receiving the request, the registration center will store the address port and other related information of the executor in the cache of the management center by cluster storage group. Users can view the information of the successfully registered executors through the management center interface, and can send tasks to the executors for execution. After the executor is started, it will send heartbeat detection transactions to the registration center at regular intervals. After receiving the heartbeat, the registration center will refresh the timestamp of the executor information in the cache. The executors that have not been refreshed after the timeout are considered unavailable and will be cleared from the cache. Fig. 9 The heartbeat detection transaction sent by the executor to the registration center is marked with a dotted line.

[0069] The user selects the code to be executed and the target executor (machine) on the interface. After the task execution is triggered, the management center initiates task scheduling and sends the task information (including source code, task type, etc.) to the target executor. After receiving the task, the target executor starts execution and feeds back the execution result to the management center ( Fig.10 dotted line mark).

[0070] The code dynamic loading execution system provided by the present invention is flexible in deployment and can be deployed independently or integrated with other systems in the form of plug-ins; it supports users to develop codes online and supports multi-version management of source codes; its open design facilitates integration with other systems and subsequent functional expansion, such as log management can be easily connected to a monitoring platform.

[0071] The abbreviations and terms in the present invention are explained as follows:

[0072] Dynamic loading: The process of loading programs and data from external storage or the network into the main memory as needed during the operation of a computer software system.

[0073] Hot update: Hot update is the dynamic distribution of code, which allows developers to fix bugs and release features without releasing a new version.

[0074] CLASS: A keyword in computer object-oriented programming languages ​​(such as Java) used to represent a class. A class is a template that describes the behavior and state of a class of objects.

[0075] CLASS instance: In a computer object-oriented programming language (such as Java), an object created by a template class.

[0076] JDK: A software development kit for the Java language, mainly used for Java applications on mobile devices and embedded devices.

[0077] WebUI: Web interface for users.

[0078] Groovy: An agile, dynamic language for the Java virtual machine.

[0079] Spring: A currently mainstream open source enterprise-level Java application development framework and one of the most successful frameworks in the Java world.

[0080] JAR: A software package file format, commonly used to aggregate a large number of Java class files, related metadata and resource (text, pictures, etc.) files into one file for the development of Java platform application software or libraries.

[0081] API: Application Programming Interface is a set of definitions, programs and protocols that enable mutual communication between computer software through the API interface.

[0082] Obviously, the above embodiments are merely examples for the purpose of clear explanation and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived therefrom are still within the scope of protection of the present invention.

Claims

1. A method for dynamically loading and executing code, characterized in that: include: Get the code to be executed and the task type; When the task type is Spring mode, after the cache verification is passed, the code to be executed is loaded using the Groovy class loader, a Class object is constructed and a new instance is created, each domain value of the new instance is replaced with the domain value corresponding to the old instance, and the new instance with the updated domain value is used to update the Spring container Bean factory.

2. The method for dynamically loading and executing code according to claim 1, characterized in that: When the task type is the Bean mode, the Groovy class loader is used to load the code to be executed, construct a Class object and create a new instance, and call the interface method of the instance to implement task processing.

3. The method for dynamically loading and executing code according to claim 1, characterized in that: When the task type is command mode, a subprocess is created to execute the task.

4. The method for dynamically loading and executing code according to claim 1, characterized in that: The cache verification includes: The MD5 value of the code to be executed is calculated and compared with the MD5 value of the code in the cache. If there is no identical MD5 value, it is determined that the code to be executed does not exist in the cache and the cache check passes. Otherwise, the cache check fails.

5. A code dynamic loading executor, characterized in that: include: The task information acquisition module is used to obtain the code to be executed and the task type; The execution module, when the task type is Spring mode, is used to use the Groovy class loader to load the code to be executed after the cache verification passes, construct a Class object and create a new instance, replace the domain values ​​of the new instance with the domain values ​​corresponding to the old instance, and update the Spring container Bean factory with the new instance after the domain values ​​are updated.

6. A code dynamic loading execution system, characterized in that: include: A user interface, used to accept user instructions; A management center, used for sending the user instruction to the target executor; The code dynamic loading executor as described in claim 5 is used to execute tasks according to the user instructions and return the execution results and execution logs to the management center.

7. The code dynamic loading and execution system according to claim 6, characterized in that: The management center includes user management, and the user management includes role management, authority management and account management.

8. The code dynamic loading and execution system according to claim 6, characterized in that: The management center also includes log management, which includes log viewing, log cleaning and log transmission.

9. The code dynamic loading and execution system according to claim 6, characterized in that: The management center also includes source code management, which includes the creation, viewing, modification and deletion of codes.

10. The code dynamic loading and execution system according to claim 6, characterized in that: The management center also includes executor management, and the executor management includes executor registration and executor scheduling.

Citation Information

Patent Citations

  • Distributed configuration center and JAVA running instance replacement method thereof

    CN114594972A