A Java program dynamic update method, device, equipment, medium and product
Through the class knowledge graph and class loader decision tree, dynamically obtain and load the latest version of Java program class loader, the problem of restarting Java program updates is solved, and dynamic updates without restart are achieved.
Patent Information
- Application Number
- CN202510695412.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-28
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2045-05-28
AI Technical Summary
The existing Java program update requires restarting the program, which cannot meet the business needs in scenarios such as grayscale release and dynamic update.
Through the class knowledge graph and class loader decision tree, dynamically obtain and load the latest version of the target class file, and realize dynamic updates without restarting the program.
It implements dynamic updates of Java programs without restarting, meeting the business needs of grayscale release and dynamic updates.
Smart Images

Figure CN120215996B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a Java program dynamic update method, device, equipment, medium and product. Background Art
[0002] During the running of a Java application, it is often necessary to call the class object of the Java program. This requires that the class file associated with the class object be loaded into the virtual machine in advance when the program starts.
[0003] In some cases, a running program needs to be updated. After the update, the running program must be restarted to load the updated class files. This program update method cannot meet actual business needs in scenarios such as grayscale releases, program debugging, and dynamic updates. Summary of the Invention
[0004] The present invention provides a Java program dynamic update method, device, equipment, medium and product to solve the problem that the program needs to be restarted when the program is updated, which cannot meet business needs in scenarios such as grayscale release and dynamic update.
[0005] According to one aspect of the present invention, a method for dynamically updating a Java program is provided, comprising:
[0006] In response to a target class file being called, obtaining information of a class loader associated with the latest version of the target class file in a class knowledge graph; the class knowledge graph includes class files and class knowledge information associated with the class files, and the class knowledge information includes information of a path where the class file is located and a class loader associated with the path;
[0007] If there is no information about the class loader associated with the latest version of the target class file in the class knowledge graph, searching the class loader associated with the target class file in the class loader decision tree as the target class loader; the class loader decision tree is constructed based on the execution order of the custom class loader and the default loading system of the current application;
[0008] The target class file is loaded through the target class loader.
[0009] According to another aspect of the present invention, there is provided a Java program dynamic update device, comprising:
[0010] A knowledge graph query module is configured to, in response to a target class file being called, obtain information about a class loader associated with the latest version of the target class file in a class knowledge graph; the class knowledge graph includes class files and class knowledge information associated with the class files, and the class knowledge information includes information about the path where the class file is located and the class loader associated with the path;
[0011] A class loader determination module is configured to search a class loader associated with the target class file in a class loader decision tree as a target class loader if no information about the class loader associated with the latest version of the target class file exists in the class knowledge graph; the class loader decision tree is constructed based on the execution order of the custom class loaders and the default loading system of the current application;
[0012] The class file loading module is used to load the target class file through the target class loader.
[0013] According to another aspect of the present invention, an electronic device is provided, comprising:
[0014] at least one processor; and
[0015] a memory communicatively connected to the at least one processor; wherein,
[0016] The memory stores a computer program that can be executed by the at least one processor. The computer program is executed by the at least one processor so that the at least one processor can execute the Java program dynamic update method described in any embodiment of the present invention.
[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the Java program dynamic update method described in any embodiment of the present invention when executed.
[0018] According to another aspect of the present invention, a computer program product is provided, including a computer program. When the computer program is executed by a processor, the computer program implements the Java program dynamic update method of any embodiment of the present disclosure.
[0019] The technical solution of an embodiment of the present invention is that in response to the target class file being called, information of the class loader associated with the latest version of the target class file is obtained in the class knowledge graph. If information of the class loader associated with the latest version of the target class file does not exist in the class knowledge graph, the class loader associated with the target class file is searched in the class loader decision tree as the target class loader. Finally, the target class file is loaded through the target class loader. When the target class file is updated, routing is performed from the class loader decision tree to find the class loader associated with the target class file to realize dynamic update of the application.
[0020] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present invention, nor is it intended to limit the scope of the present invention. Other features of the present invention will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0022] Figure 1 This is a flowchart of a Java program dynamic update method provided according to the first embodiment of the present invention;
[0023] Figure 2a This is a flowchart of a Java program dynamic update method provided in accordance with the second embodiment of the present invention;
[0024] Figure 2b This is a schematic diagram of the structure of a class loader decision tree provided in Embodiment 2 of the present invention;
[0025] Figure 3 This is a structural diagram of a Java program dynamic update device provided according to a third embodiment of the present invention;
[0026] Figure 4 The present invention is a schematic diagram of the structure of an electronic device for implementing the Java program dynamic update method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0027] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described 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 making creative efforts should fall within the scope of protection of the present invention.
[0028] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention 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 numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes 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.
[0029] Example 1
[0030] Figure 1 A flowchart of a Java program dynamic update method is provided for the first embodiment of the present invention. This embodiment is applicable to the case where a class file in a Java application is updated and the updated class file is dynamically loaded through a class knowledge graph and a class loader decision tree. The method can be executed by a Java program dynamic update device, which can be implemented in the form of hardware and / or software and can be configured in various general-purpose computing devices. Figure 1 As shown, the method includes:
[0031] S110. In response to the target class file being called, information on the class loader associated with the latest version of the target class file is obtained in the class knowledge graph; the class knowledge graph includes the class file and class knowledge information associated with the class file, and the class knowledge information includes information on the path where the class file is located and the class loader associated with the path.
[0032] A class knowledge graph is a language network that describes the relationships between class resources and their associated class knowledge in a structured format. Class resources can be class files in a Java program or JAR files, which contain at least one class file. Class knowledge information includes the class resource's file size, path, creation time, and information about the class loader associated with that path.
[0033] For example, the class knowledge graph includes class files, as well as information about the file size, path, and class loader associated with the class files. The class knowledge graph may also include jar packages, as well as information about the file size, path, and class loader associated with the jar packages.
[0034] To ensure the accuracy of the class knowledge graph, a monitoring mechanism (watch mechanism) can be set up for class resources. When class resource updates are detected, the class knowledge graph is updated accordingly and the updated class knowledge information and version are stored accordingly. The granularity of the monitoring mechanism can be set as needed, for example, it can be set to the class file granularity or the JAR package granularity.
[0035] In an embodiment of the present invention, during program execution, when a target class file is called, the class knowledge information associated with the called target class file is first queried in the class knowledge graph. The information of the class loader associated with the latest version of the target class file is queried in the class knowledge information. If the information of the class loader associated with the latest version of the target class file is found, it indicates that the latest version of the target class file has been loaded, and no update has occurred between the target class file being called this time and the last time it was called. If the information of the class loader associated with the latest version of the target class file is not found in the class knowledge graph, it indicates that the latest version of the target class file has not been loaded, and an update has occurred between the target class file being called this time and the last time it was called.
[0036] Optionally, in an embodiment of the present invention, the following further comprises:
[0037] Based on the class loading path in the Java configuration file, determine the path, file size, and creation time of each class resource;
[0038] Build a class knowledge graph based on the class resource path, file size, and creation time;
[0039] The class knowledge graph includes class knowledge information associated with class resources in the application. The class knowledge information includes the size, path, and creation time of the class resources.
[0040] In this optional embodiment, before running the program, the developer creates a Java configuration file in the current program's working directory. The configuration file configures the class loading path and the execution order of custom class loaders. If no configuration file is specified, the default parameters are set using the class path of the main class being run. The class loading path is then searched upwards to determine the application's JAR library path.
[0041] Build a resource scheduler in the application, and when the main class of the program is running, set the current class loader to the resource scheduler for class resource loading.
[0042] During application initialization, the class loading path in the Java configuration file is used to determine the path, file size, and creation time of each class resource. This information is then used to construct a class knowledge graph based on the path, file size, and creation time of each class resource. This class knowledge graph includes class knowledge information associated with class resources in the application, including their size, location, and creation time.
[0043] Optionally, the embodiment of the present invention further includes:
[0044] Add a monitoring mechanism to the class resources in the application. When the class resources are updated, the class knowledge information of the class resources in the class knowledge graph is updated, and the updated class resource version is recorded.
[0045] Class resources are class files or jar packages; class knowledge information includes the file size, update time, path, and class loader information associated with the path of the class resource.
[0046] In this optional embodiment, in order to ensure the accuracy of the class knowledge information in the class knowledge graph and realize the dynamic update of the application, a monitoring mechanism is added to the class resources in the application. When the class resource update is detected, the class knowledge information of the class resource in the class knowledge graph is updated, and the updated class resource version is recorded. Specifically, when a class resource is deleted, the deleted class resource can be pruned in the class knowledge graph; when a class resource is modified, the class knowledge information associated with the modified class resource can be updated in the class knowledge graph. The class resource version is incremented by 1 after each update.
[0047] Class resources are class files or JAR files. Class knowledge includes the class resource's file size, update time, path, and the class loader associated with that path. The monitoring mechanism's granularity can be customized based on actual needs, for example, to class file or JAR file granularity.
[0048] It's worth noting that the class loader information associated with the path is stored in the class knowledge graph when the class resource is first loaded. By adding a monitoring mechanism to the class resource, the class knowledge graph can be updated in a timely manner when the class resource is updated, providing data for dynamic application updates.
[0049] S120. When there is no information about the class loader associated with the latest version of the target class file in the class knowledge graph, search the class loader associated with the target class file in the class loader decision tree as the target class loader; the class loader decision tree is constructed based on the execution order of the custom class loader and the default loading system of the current application.
[0050] The class loader decision tree is a tree structure constructed based on the execution order of custom class loaders and the default class loader hierarchy of the current application. It describes class loading priority and delegation logic. The execution order of custom class loaders is pre-defined by the developer in the Java configuration file and includes at least one custom class loader and the execution order of custom class loaders. The default class loader hierarchy of the current application is the default loader hierarchy that matches the application type.
[0051] In an embodiment of the present invention, when there is no information about the class loader associated with the latest version of the target class file in the class knowledge graph, it indicates that the latest version of the target class file has been updated and has not been loaded after the update. At this time, the class loader associated with the target class file can be found in the class loader decision tree as the target class loader. Specifically, routing can be performed from the leaf node in the class loader decision tree, and a version instance of each class loader can be created during the routing process until the class loader associated with the target class file is found as the target loader. Among them, the class loader associated with the target class file is the class loader associated with the path where the target class file is located, and is used to load the class file under the path where the target class file is located.
[0052] In addition, the information of determining the target class loader can be added to the class knowledge graph, so that when the target class file is called subsequently, the information of the class loader associated with the latest version of the target class file can be directly found from the class knowledge graph to realize fast loading and calling of the class file.
[0053] S130. Load the target class file through the target class loader.
[0054] In the embodiment of the present invention, after the target class loader is determined, the target class loader is set as a resource scheduler to load the target class file and complete the target class file call.
[0055] The technical solution of an embodiment of the present invention is that in response to the target class file being called, information of the class loader associated with the latest version of the target class file is obtained in the class knowledge graph. If information of the class loader associated with the latest version of the target class file does not exist in the class knowledge graph, the class loader associated with the target class file is searched in the class loader decision tree as the target class loader. Finally, the target class file is loaded through the target class loader. When the target class file is updated, routing is performed from the class loader decision tree to find the class loader associated with the target class file to realize dynamic update of the application.
[0056] Example 2
[0057] Figure 2a This is a flowchart of a Java program dynamic update method provided in the second embodiment of the present invention. This embodiment further refines the above embodiment and provides the specific steps of searching the class loader associated with the target class file in the class loader decision tree as the target class loader, and the specific steps before obtaining the information of the class loader associated with the latest version of the target class file in the class knowledge graph. Figure 2a As shown, the method includes:
[0058] S210. Obtain the execution order of the custom class loader in the Java configuration file.
[0059] The Java configuration file is created by the developer in the current program's working directory before the program runs. It includes the class loading path and the execution order of custom class loaders. If the configuration file is not configured, the default parameters are set based on the class path of the main class running. The class loading path is then used to search upwards to determine the application's JAR library path.
[0060] In an embodiment of the present invention, in the resource routing management of application initialization, the execution order of the custom class loaders is first obtained in the Java configuration file, including the custom class loader A and the custom class loader B, as well as the execution order of the custom class loaders.
[0061] S220: Determine a default class loading system associated with the program type according to the program type of the current application.
[0062] Application types can include stand-alone programs and web applications, and different types of applications correspond to different default class loading systems.
[0063] In the embodiment of the present invention, the default class loading system associated with the program type is determined based on the program type of the current application. For example, in the default class loading system of a web application, the class loaders can be arranged in the following order of execution: application class loader AppClassLoader, extension class loader ExtClassLoder, and startup class loader BootstrapClassLoder.
[0064] S230: Construct a class loader decision tree according to the execution order of the custom class loader and the default loading system.
[0065] In the embodiment of the present invention, a class loader decision tree is constructed based on the execution order of the custom class loader and the default loading system. Figure 2b As shown in the figure, a class loader decision tree is constructed based on the execution order of custom class loaders and the default loading system. Custom class loaders are executed before class loaders in the default loading system. By establishing a class loader decision tree, subsequent class file loading can be performed according to the order in the decision tree, improving class file loading efficiency.
[0066] Optionally, the embodiment of the present invention further includes:
[0067] Add a monitoring mechanism to the class resources in the application. When a class resource update is detected, the class knowledge information of the class resource in the class knowledge graph is updated and the updated class resource version is recorded.
[0068] Class resources are class files or jar packages; class knowledge information includes the file size, update time, path, and class loader information associated with the path of the class resource.
[0069] S240. In response to the target class file being called, information on the class loader associated with the latest version of the target class file is obtained in the class knowledge graph; the class knowledge graph includes the class file and the class knowledge information associated with the class file, and the class knowledge information includes the path where the class file is located and information on the class loader associated with the path.
[0070] S250. When there is no information about the class loader associated with the latest version of the target class file in the class knowledge graph, routing is performed starting from the leaf node of the class loader decision tree to query the class loader associated with the target class file as the target class loader; the class loader decision tree is constructed based on the execution order of the custom class loader and the default loading system of the current application.
[0071] In an embodiment of the present invention, if the class knowledge graph does not contain information about the class loader associated with the latest version of the target class file, it is necessary to route from the leaf node of the class loader decision tree and query the class loader associated with the target class file as the target class loader. Each class loader in the class loader decision tree corresponds to one or more class loading paths.
[0072] S260. Associate the target class loader information with the path of the target class file and store them in the class knowledge graph as the class knowledge information of the latest version of the target class file.
[0073] In this embodiment of the present invention, after determining the target class loader in the class loader decision tree, the target class loader information is further associated with the path to the target class file and stored in the class knowledge graph as the latest version of the class knowledge information of the target class file. When the target class file is subsequently called, the corresponding class loader can be directly obtained from the class knowledge graph for class resource scheduling.
[0074] Optionally, the embodiment of the present invention further includes:
[0075] When the class knowledge graph does not contain the target class file, obtain the call point of the target class file and search the class knowledge graph for the target version of the class loader associated with the call point.
[0076] In the class loader decision tree, candidate class loaders having the same version as or smaller than the target version are obtained, and the target class loader is determined among the candidate class loaders.
[0077] In this optional embodiment, when searching for knowledge information of the called target class file in the class knowledge graph, it is also possible that the class knowledge graph does not contain the target file. This may be because the target class file has been deleted in the latest program change. In this case, it is necessary to obtain the calling point of the target class file and search the class knowledge graph for the target version of the class loader associated with the calling point. Furthermore, in the class loader decision tree, candidate class loaders that are the same as the target version and smaller than the target version are obtained, and the target class loader is determined among the candidate class loaders.
[0078] In a specific example, when class file A with version number 4 calls class file B with version number 5, it is necessary to search for class file B with version number 5 and its associated class knowledge information in the class knowledge graph. At this time, if class file B does not appear in the class knowledge graph, it means that class file B was deleted during the fifth update, and the class knowledge graph will be pruned to delete class file B and its associated class knowledge information. At this time, it is necessary to obtain the reference path for loading class file B in the application, and determine the call point based on the reference path. At this time, class file A that calls class file B can be used as the call point. Further, the knowledge information of class file A with version number 4 is searched in the class knowledge graph, and the information of the class loader associated with class file A with version number 4 is obtained from the knowledge information, and the version of the obtained class loader is used as the target version, that is, the target version is 4 at this time. Finally, in the class loader decision tree, candidate class loaders with the same or smaller version than the target version are obtained, and the class loader associated with class file B is determined as the target class loader among the candidate class loaders.
[0079] Optionally, also include:
[0080] If there is no information about the class loader associated with the latest version of the target class file in the class knowledge graph, a progressive release strategy is searched in a preset Java configuration file;
[0081] If the Java configuration file contains a progressive release strategy, the class knowledge graph is detected according to the set time period;
[0082] When the file size and update time of the target class file are the same as the historical version of the target class file, in the class knowledge graph, the class knowledge information associated with the latest version of the target class file is uninstalled, and in the class loader decision tree, the class loader information associated with the latest version of the target class file is uninstalled.
[0083] In this optional embodiment, when the class knowledge graph does not contain information about the class loader associated with the latest version of the target class file, it is also necessary to search for a progressive release strategy in a preset Java configuration file. If the Java configuration file contains a progressive release strategy, such as blue-green release or canary release, it indicates that the new version of the application is in the gradual release stage and version rollback may occur. At this time, it is necessary to detect the class knowledge graph according to a set time period. When the file size and update time of the target class file are the same as the historical version of the target class file, it is considered that a version rollback has occurred. At this time, in the class knowledge graph, the class knowledge information associated with the latest version of the target class file is unloaded, and in the class loader decision tree, the information about the class loader associated with the latest version of the target class file is unloaded, so that when the subsequent application is running, the class file is called according to the last version that has been rolled back. By continuously scanning the class knowledge graph during the progressive release process, the knowledge information of the class resources in the class knowledge graph and the information in the class loader decision tree can be promptly changed when a version rollback occurs. This can ensure dynamic updates while meeting the requirements of version rollback in the progressive release process.
[0084] Optionally, if the progressive release strategy in the Java configuration file is canary release, the following is also included:
[0085] Record the number of class loaders associated with the latest version of the target class file and the previous version of the latest version;
[0086] When the ratio of the number of class loaders associated with the latest version to the previous version reaches the target ratio, the canary release strategy is exited.
[0087] In this optional embodiment, if the progressive release strategy configured in the Java configuration file is canary release, it indicates that the release link at this time is to gradually open the new version of the application according to a certain ratio. At this time, the latest version of the target class file, such as version 5, and the previous version of the latest version, version 4, and the number of class loaders associated with them are recorded. When the ratio of the number of class loaders associated with the latest version and the previous version reaches the target ratio, for example, 5:5, the canary release strategy is exited, and the complete new version is released subsequently. During this period, if a version rollback occurs, the relevant information of the class knowledge graph and the class loader decision tree is rolled back.
[0088] When the application update exceeds the set time and there is no version rollback, it is considered to be released successfully. The historical version of the class loader in the class loader decision tree is automatically uninstalled, and the knowledge information of the class resource is written in the class knowledge graph.
[0089] In the above situation, if a class file cannot be found in the class knowledge graph, it is judged as an abnormal mode, and it is necessary to obtain the calling path of the class file to determine the calling point, and then obtain the path of the calling point in the class knowledge graph, the path-associated class loader, and the target class library to which the calling point belongs. Furthermore, the version of the class loader associated with the calling point is increased by 1, and the target class library to which the calling point belongs is triggered, and the latest version of the class loader associated with all class files under the target class library is mounted. Finally, the latest version of the mounted class loader is used to trigger the loading of the class file in the target class library, completing the loading of the class file, which serves as the class resource basis for the subsequent application runtime.
[0090] In a specific example, if class file A loads class file B, and class file B does not exist in the class knowledge graph, the path to class file A is obtained from the class knowledge graph, along with the class loader associated with the path and the target class library to which class file A belongs. Furthermore, the version of the class loader associated with class file A is incremented by 1 (for example, from the initial version 4 to version 5), and the target class library to which class file A belongs is triggered. The latest version of the resource-associated class loader (version 5) is mounted within the target class library. Finally, the latest version of the class loader is used to trigger the loading of the class file in the class library, loading the class file into memory.
[0091] S270. Load the target class file through the target class loader.
[0092] The technical solution of an embodiment of the present invention is that in response to the target class file being called, information of the class loader associated with the latest version of the target class file is obtained in the class knowledge graph. If the information of the class loader associated with the latest version of the target class file does not exist in the class knowledge graph, routing is performed from the leaf node of the class loader decision tree, and the class loader associated with the target class file is queried as the target class loader. The information of the target class loader is associated with the path where the target class file is located and stored in the class knowledge graph. As the class knowledge information of the latest version of the target class file, the loading of the latest version of the target class file can be completed, and dynamic update of the application can be realized.
[0093] Example 3
[0094] Figure 3 This is a schematic diagram of a Java program dynamic update device provided by the third embodiment of the present invention. Figure 3 As shown, the device includes:
[0095] The knowledge graph query module 310 is configured to obtain, in response to a target class file being called, information about a class loader associated with the latest version of the target class file in the class knowledge graph; the class knowledge graph includes class files and class knowledge information associated with the class files, and the class knowledge information includes information about the path of the class file and the class loader associated with the path;
[0096] A first class loader determination module 320 is configured to search a class loader associated with the target class file as a target class loader in a class loader decision tree when no information about the class loader associated with the latest version of the target class file exists in the class knowledge graph; the class loader decision tree is constructed based on the execution order of the custom class loaders and the default loading system of the current application;
[0097] The class file loading module 330 is configured to load the target class file through the target class loader.
[0098] The technical solution of an embodiment of the present invention is that in response to the target class file being called, information of the class loader associated with the latest version of the target class file is obtained in the class knowledge graph. If information of the class loader associated with the latest version of the target class file does not exist in the class knowledge graph, the class loader associated with the target class file is searched in the class loader decision tree as the target class loader. Finally, the target class file is loaded through the target class loader. When the target class file is updated, routing is performed from the class loader decision tree to find the class loader associated with the target class file to realize dynamic update of the application.
[0099] Optionally, the first class loader determination module 320 is specifically configured to:
[0100] Routing from the leaf node of the class loader decision tree, querying the class loader associated with the target class file as the target class loader;
[0101] The information of the target class loader is associated with the path where the target class file is located and stored in the class knowledge graph as the class knowledge information of the latest version of the target class file.
[0102] Optionally, the Java program dynamic update device further includes:
[0103] A release strategy reading module, configured to search for a progressive release strategy in a preset Java configuration file when there is no information of a class loader associated with the latest version of the target class file in the class knowledge graph;
[0104] A knowledge graph detection module is used to detect the class knowledge graph according to a set time period if the Java configuration file contains a progressive release strategy;
[0105] The version rollback module is used to unload the class knowledge information associated with the latest version of the target class file in the class knowledge graph when the file size and update time of the target class file are the same as the historical version of the target class file, and to unload the class loader information associated with the latest version of the target class file in the class loader decision tree.
[0106] Optionally, the Java program dynamic update device further includes:
[0107] a target version determination module, configured to obtain a call point of the target class file when the target class file is not included in the class knowledge graph, and search the class knowledge graph for a target version of a class loader associated with the call point;
[0108] The second class loader determination module is configured to obtain candidate class loaders with the same version as or smaller than the target version in the class loader decision tree, and determine a target class loader from the candidate class loaders.
[0109] Optionally, the Java program dynamic update device further includes:
[0110] The class resource monitoring module is used to add a monitoring mechanism to the class resources in the application. When the class resource is updated, the class knowledge information of the class resource in the class knowledge graph is updated and the updated class resource version is recorded.
[0111] The class resource is a class file or a jar package; the class knowledge information includes the file size, update time, path and class loader information associated with the path of the class resource.
[0112] Optionally, the Java program dynamic update device further includes:
[0113] An execution order determination module, configured to obtain the execution order of the custom class loaders in the Java configuration file before obtaining information of the class loader associated with the latest version of the target class file in the class knowledge graph;
[0114] A default class loading system determination module is used to determine the default class loading system associated with the program type according to the program type of the current application;
[0115] The class loader decision tree construction module is used to construct a class loader decision tree according to the execution order of the custom class loader and the default loading system.
[0116] Optionally, the Java program dynamic update device further includes:
[0117] A load quantity recording module is used to record the load quantity of the class loader associated with the latest version of the target class file and the previous version of the latest version when the progressive release strategy in the Java configuration file is canary release;
[0118] The release exit module is used to exit the canary release strategy when the ratio of the number of loads of the class loaders associated with the latest version and the previous version reaches a target ratio.
[0119] The Java program dynamic update device provided by the embodiment of the present invention can execute the Java program dynamic update method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0120] In the technical solution of the present invention, the information collected is information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of the relevant data comply with the relevant laws, regulations and standards of the relevant countries and regions, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0121] Example 4
[0122] According to an embodiment of the present invention, the present invention further provides an electronic device, a readable storage medium and a computer program product.
[0123] Figure 4 A schematic diagram of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, appliances, blade appliances, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or claimed herein.
[0124] like Figure 4As shown, electronic device 10 includes at least one processor 11 and memory, such as read-only memory (ROM) 12 and random access memory (RAM) 13, communicatively connected to at least one processor 11. The memory stores computer programs executable by the at least one processor. Processor 11 can perform various appropriate actions and processes based on the computer programs stored in ROM 12 or loaded from storage unit 18 into RAM 13. RAM 13 can also store various programs and data required for the operation of electronic device 10. Processor 11, ROM 12, and RAM 13 are interconnected via bus 14. An input / output (I / O) interface 15 is also connected to bus 14.
[0125] Multiple components in the electronic device 10 are connected to the I / O interface 15, including an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a magnetic disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0126] Processor 11 can be any general-purpose and / or specialized processing component with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any other suitable processor, controller, microcontroller, etc. Processor 11 executes the various methods and processes described above, such as the Java program dynamic update method.
[0127] In some embodiments, the Java program dynamic update method can be implemented as a computer program tangibly embodied in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the Java program dynamic update method described above can be performed. Alternatively, in other embodiments, processor 11 can be configured to perform the Java program dynamic update method in any other suitable manner (e.g., via firmware).
[0128] Various embodiments of the systems and techniques described above can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0129] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer program is executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer program may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or application.
[0130] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or apparatus. A computer-readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or apparatus, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media may include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0131] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device that has: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0132] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data applier), or a computing system that includes middleware components (e.g., an application applier), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0133] A computing system may include clients and applications. These clients and applications are typically remote from each other and typically interact via a communication network. This client-application relationship is established by computer programs running on the respective computers, establishing a client-application relationship. The application can be a cloud application, also known as a cloud computing application or cloud host. This is a host product within a cloud computing application ecosystem that addresses the management difficulties and limited scalability of traditional physical hosting and VPS applications.
[0134] The present application also discloses a computer program product, comprising a computer program that, when executed by a processor, implements the Java program dynamic update method provided in any of the embodiments of the present application. This program product and the Java program dynamic update method disclosed in each embodiment of the present application share the same inventive concept and are therefore not further described here.
[0135] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in the present invention can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved. This is not limited herein.
[0136] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.
Claims
1. A Java program dynamic update method, characterized in that: include: In response to the target class file being called, obtaining information of a class loader associated with the latest version of the target class file in the class knowledge graph; The class knowledge graph is a language network that describes the relationship between class resources and class knowledge information associated with class resources in a structured form. The class knowledge graph includes class files and class knowledge information associated with class files. The class knowledge information includes the path where the class file is located and information about the class loader associated with the path. If there is no information about the class loader associated with the latest version of the target class file in the class knowledge graph, indicating that the latest version of the target class file has been updated and has not been loaded after the update, the class loader associated with the target class file is searched in the class loader decision tree as the target class loader; the class loader decision tree is constructed based on the execution order of the custom class loader and the default loading system of the current application; Loading the target class file through the target class loader; The step of searching a class loader associated with the target class file in a class loader decision tree as a target class loader includes: Routing from the leaf node of the class loader decision tree, querying the class loader associated with the target class file as the target class loader; The information of the target class loader is associated with the path where the target class file is located and stored in the class knowledge graph as the class knowledge information of the latest version of the target class file.
2. The Java program dynamic update method according to claim 1, characterized in that: Also includes: If there is no information of a class loader associated with the latest version of the target class file in the class knowledge graph, searching for a progressive release strategy in a preset Java configuration file; If the Java configuration file contains a progressive release strategy, the class knowledge graph is detected according to a set time period; When the file size and update time of the target class file are the same as the historical version of the target class file, in the class knowledge graph, the class knowledge information associated with the latest version of the target class file is uninstalled, and in the class loader decision tree, the information of the class loader associated with the latest version of the target class file is uninstalled.
3. The Java program dynamic update method according to claim 1, characterized in that: Also includes: In the case that the target class file is not included in the class knowledge graph, obtaining the call point of the target class file, and searching the class knowledge graph for the target version of the class loader of the class file associated with the call point; In the class loader decision tree, candidate class loaders with the same version as the target version and a version smaller than the target version are obtained, and a target class loader is determined among the candidate class loaders.
4. The Java program dynamic update method according to claim 1, characterized in that: Also includes: Add a monitoring mechanism to the class resources in the application. When the class resources are updated, the class knowledge information of the class resources in the class knowledge graph is updated, and the updated class resource version is recorded. The class resource is a class file or a jar package; the class knowledge information includes the file size, update time, path and class loader information associated with the path of the class resource.
5. The Java program dynamic update method according to claim 1, characterized in that: Before obtaining information of a class loader associated with the latest version of the target class file in the class knowledge graph, the method further includes: Get the execution order of custom class loaders in the Java configuration file; Determine, based on the program type of the current application, a default class loading system associated with the program type; A class loader decision tree is constructed according to the execution order of the custom class loader and the default loading system.
6. The Java program dynamic update method according to claim 2, characterized in that: If the progressive release strategy in the Java configuration file is canary release, the following is also included: Record the number of class loaders associated with the latest version of the target class file and the previous version of the latest version; When the ratio of the number of loads of the class loaders associated with the latest version and the previous version reaches the target ratio, the canary release strategy is exited.
7. A Java program dynamic update device, characterized in that: include: A knowledge graph query module is configured to, in response to a target class file being called, obtain information about a class loader associated with the latest version of the target class file in a class knowledge graph; the class knowledge graph is a language network that describes the relationship between class resources and class knowledge information associated with the class resources in a structured form, the class knowledge graph includes class files and class knowledge information associated with the class files, and the class knowledge information includes information about the path of the class file and the class loader associated with the path; A first class loader determination module is configured to, when there is no information in the class knowledge graph about a class loader associated with the latest version of the target class file, indicate that the latest version of the target class file has been updated and has not been loaded after the update, search a class loader decision tree for a class loader associated with the target class file as a target class loader; the class loader decision tree is constructed based on the execution order of the custom class loaders and the default loading system of the current application; A class file loading module, configured to load the target class file through the target class loader; The first class loader determination module is specifically used to: Routing from the leaf node of the class loader decision tree, querying the class loader associated with the target class file as the target class loader; The information of the target class loader is associated with the path where the target class file is located and stored in the class knowledge graph as the class knowledge information of the latest version of the target class file.
8. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor. The computer program is executed by the at least one processor so that the at least one processor can execute the Java program dynamic update method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the Java program dynamic update method according to any one of claims 1 to 6 when executed.
10. A computer program product, characterized in that The computer program product includes a computer program, and when the computer program is executed by a processor, the computer program implements the Java program dynamic update method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Hot-load method and device and information system
CN102819438A
Hot updating method and apparatus
CN107179925A