File hot loading method and device, computer equipment and storage medium
Through the file hot loading method, the problem of the existing technology that the code cannot be updated without interrupting services is solved, dynamic configuration updates and stability improvements in enterprise-level applications are achieved, and non-stop updates and dynamic function expansion of Java applications are supported.
Patent Information
- Application Number
- CN202510366758.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-26
- Publication Date
- 2025-07-11
AI Technical Summary
The prior art cannot realize hot loading of files, especially in enterprise-level applications that cannot be easily shut down, resulting in interruption of services when updating codes, affecting business continuity.
Provides a file hot loading method, including obtaining configuration information, performing pre-checking, security verification, whitelist judgment, file sorting and hot loading operations, adopting a loop loading mechanism, and having a fallback function in case of failure to ensure the reliability and stability of loading.
It realizes dynamic update of configuration files without interrupting services, prevents illegal or incompatible file loading, improves resource utilization efficiency and load targetedness, reduces the risk of system failure, and supports Java applications' non-stop updates and dynamic function expansion.
Smart Images

Figure CN120295690A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of R & D management development assistance technology and medical health technology, and particularly relates to a file hot loading method, device, computer device and storage medium. Background Art
[0002] In some enterprise-level applications that cannot be easily shut down, such as medical systems, bank systems, and background services of large e-commerce platforms, when certain function modules in a hospital's settlement system, scheduling system, etc. need to be updated (such as adding new business rules, modifying data processing algorithms), the hot loading technology can update the code without interrupting the service, thereby ensuring the normal operation of the hospital. This can avoid inconveniencing users due to downtime updates and reduce the negative impact on business; many Java applications need to dynamically adjust configurations or logic according to changes in the external environment. For example, a service discovery and configuration management component in a distributed system needs to update its configuration in real time according to changes in the cluster status. Hot loading can be used to dynamically load new configuration files or update configuration objects, enabling the system to quickly adapt to these changes without restarting the entire service..
[0003] Currently, there are relatively few related products in the industry, such as jrebel and springloaded, but both require integration with an IDE to achieve hot deployment and cannot achieve file hot loading. These industry products are either ready-made complex open-source projects or closed commercial projects, and it is difficult to modify and match the company's projects by oneself. Summary of the Invention
[0004] The purpose of the present invention is to overcome the above technical deficiencies, and provide a file hot loading method, device, computer device and storage medium applicable to fields such as medical health or fintech technology, and solve the technical problem that file hot loading cannot be achieved in the prior art.
[0005] To achieve the above technical objectives, the present invention adopts the following technical solutions:
[0006] In a first aspect, the present invention provides a file hot loading method, including the following steps:
[0007] Obtain relevant configuration information for file hot loading;
[0008] Based on the relevant configuration information, perform pre-check for hot loading;
[0009] When the pre-check passes, obtain a list of files to be loaded, and perform hot loading operations on each file in the list of files to be loaded;
[0010] Judge whether the hot reload operation of each file is successful. If so, end the loading process; otherwise, perform the hot reload rollback operation and end the loading process.
[0011] In some embodiments, the pre-check for hot reload based on the relevant configuration information includes:
[0012] Perform a security check for file hot reload based on the relevant configuration information;
[0013] When the security check for file hot reload passes, perform a whitelist check for file hot reload based on the preset full class path whitelist for file hot reload.
[0014] In some embodiments, the security check for file hot reload based on the relevant configuration information includes:
[0015] Based on the switch information in the relevant configuration information, judge whether the overall switch for file hot reload is turned on;
[0016] When the overall switch for file hot reload is turned on, judge whether a distributed lock can be obtained;
[0017] When a distributed lock can be obtained, find the loading address through the cache and filter out the already loaded addresses;
[0018] After the filtering is completed, judge whether the file to be loaded can be read. If so, it means the security check passes.
[0019] In some embodiments, when the security check for file hot reload passes, the whitelist check for file hot reload based on the preset full class path whitelist for file hot reload includes:
[0020] When the security check for file hot reload passes, judge whether the file type of the file to be loaded meets the requirements;
[0021] When the file type of the file to be loaded meets the requirements, judge whether the file to be loaded is in the preset full class path whitelist for file hot reload. If so, it means the check passes.
[0022] In some embodiments, when the pre-check passes, obtain the list of files to be loaded and perform hot reload operations on each file in the list of files to be loaded, including:
[0023] When the pre-check passes, obtain the list of files to be loaded;
[0024] Based on the preset order of files in the full class path whitelist file, reorder the files in the list of files to be loaded for prime numbers to obtain the sorted list of files to be loaded;
[0025] Based on the sorted list of loaded files, perform a hot loading operation on each file in the list of loaded files.
[0026] In some embodiments, determining whether the hot loading operation of each file is successful. If so, end the loading process; otherwise, perform a hot loading rollback operation and end the loading process, including:
[0027] Determine whether the currently loaded file is successfully loaded. If so, record the loaded information. If the currently loaded file is not successfully loaded, roll back the loaded file to the version before loading and end the loading process;
[0028] Determine whether all files have been loaded. If so, end the loading process; otherwise, continue to load the next file.
[0029] In some embodiments, determining whether all files have been loaded includes:
[0030] Determine whether an error is captured during the loading process;
[0031] When no error is captured during the loading process, determine whether all class records of the loaded classes are normally recorded;
[0032] When all class records of the loaded classes are normally recorded, determine whether a rollback version operation has been triggered. If not, it is determined that all files have been loaded.
[0033] In a second aspect, the present invention further provides a file hot loading device, including:
[0034] An information acquisition module for acquiring relevant configuration information for file hot loading;
[0035] A pre-check module for performing pre-check for hot loading based on the relevant configuration information;
[0036] A file acquisition module for, when the pre-check passes, acquiring a list of loaded files and performing a hot loading operation on each file in the list of loaded files;
[0037] A judgment module for judging whether the hot loading operation of each file is successful. If so, end the loading process; otherwise, perform a hot loading rollback operation and end the loading process.
[0038] In a third aspect, the present invention further provides a computer device, including a memory and a processor. A computer-readable instruction is stored in the memory, and when the processor executes the computer-readable instruction, the steps of the file hot loading method described above are implemented.
[0039] Fourthly, the present invention further provides a computer-readable storage medium, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor, the steps of the file hot loading method described above are implemented.
[0040] Compared with the prior art, for the file hot loading method, device, computer device and storage medium provided by the present invention, first, relevant configuration information for file hot loading is obtained; then, based on the relevant configuration information, pre-hot loading verification is performed; after that, when the pre-verification passes, a list of files to be loaded is obtained, and hot loading operations are performed on each file in the list of files to be loaded; finally, it is judged whether the hot loading operations of all files are successful. If so, the loading process ends; otherwise, a hot loading rollback operation is executed and the loading process ends. The present invention can dynamically update configuration files, facilitating quick adjustment of hot loading-related settings according to different environments and requirements without redeploying the application. Through pre-verification, illegal or incompatible jar packages and class files can be effectively prevented from being loaded, ensuring the stability and security of the system. Moreover, it can achieve precise loading of required class files in a specific order, avoiding the loading of unnecessary classes, improving resource utilization efficiency and loading pertinence. By adopting a mechanism of circularly loading class files, file annotation aliases and uninstallation injection information can be processed during the loading process, and there is a rollback function in case of loading failure, ensuring the reliability of loading. Information is recorded when the loading is successful, and at the same time, abnormal situations during the loading process can be effectively handled, reducing the risk of system failures caused by hot loading failures, and overall improving the stability and controllability of hot loading operations, providing strong support for the non-stop update and dynamic function expansion of Java applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the solutions in the present invention, the following will briefly introduce the drawings required for the description of the embodiments of the present invention. Obviously, the following-described drawings are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0042] Figure 1 is an exemplary system architecture diagram in which the present invention can be applied;
[0043] Figure 2 is a flowchart of an embodiment of the file hot loading method according to the present invention;
[0044] Figure 3 is Figure 2 a flowchart of a specific embodiment of step S200 shown;
[0045] Figure 4 is Figure 2 a flowchart of a specific embodiment of step S300 shown;
[0046] Figure 5 Yes Figure 2 It is a flowchart of a specific embodiment of step S400 shown above;
[0047] Figure 6 It is a schematic structural diagram of an embodiment of a file hot loading device according to the present invention;
[0048] Figure 7 It is a schematic structural diagram of an embodiment of a computer device according to the present invention;
[0049] Figure 8 It is a schematic structural diagram of another embodiment of a computer device according to the present invention. Detailed implementation manners
[0050] In order to make the objectives, technical solutions and advantages of the present invention clearer and more understandable, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0051] Referring to "embodiments" herein means that specific features, structures or characteristics described in connection with the embodiments may be included in at least one embodiment of the present invention. The phrase appears in various places in the specification and does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein may be combined with other embodiments.
[0052] In order to enable those skilled in the art of this technology to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings.
[0053] The file hot loading method provided by the embodiments of the present invention can be applied to, for example Figure 1In the application environment, the client communicates with the server through the network. The server can obtain the relevant configuration information for file hot loading through the client; based on the relevant configuration information, perform pre-checks for hot loading; when the pre-check passes, obtain the list of files to be loaded, and perform hot loading operations on each file in the list of files to be loaded; determine whether the hot loading operations of each file are successful. If so, end the loading process. Otherwise, perform a hot loading rollback operation and end the loading process. In the present invention, for medical systems, banking systems, and large e-commerce platforms, configuration files can be dynamically updated, facilitating quick adjustment of hot loading-related settings according to different environments and requirements without redeploying the application. Through pre-checks, illegal or incompatible jar packages and class files can be effectively prevented from being loaded, ensuring system stability and security. Moreover, it is possible to accurately load the required class files in a specific order, avoid loading unnecessary classes, improve resource utilization efficiency and loading pertinence. By adopting a mechanism for circularly loading class files, file annotation aliases and unloading injection information can be processed during the loading process, and there is a rollback function in case of loading failure, which can ensure the reliability of loading. When loading is successful, information is recorded, and at the same time, abnormal situations during the loading process can be effectively handled, reducing the risk of system failures caused by hot loading failures, and overall enhancing the stability and controllability of hot loading operations, providing strong support for the non-stop update and dynamic function expansion of Java applications. Among them, the client can be, but is not limited to, various personal computers, laptop computers, smart phones, tablet computers, and portable wearable devices. The server can be implemented by an independent server or a server cluster composed of multiple servers. The present invention will be described in detail below through specific embodiments.
[0054] Please refer to Figure 2 , Figure 2 which shows a flowchart of an embodiment of the file hot loading method according to the present invention. The method described in the present invention is applicable to the background service upgrade of medical systems, banking systems, and large e-commerce platforms, and includes steps S100 to S400.
[0055] S100. Obtain the relevant configuration information for file hot loading.
[0056] In this embodiment, through the Nacos configuration center, the configuration file can be dynamically updated, which facilitates quickly adjusting the hot loading related settings according to different environments and requirements without redeploying the application. Among them, Nacos configuration is a dynamic service discovery, configuration management, and service management platform, mainly used for centrally managing the configuration information of application programs. The Nacos configuration center can centrally store the configurations scattered in each application into the Nacos server, facilitating unified viewing, modification, and management, solving the problems of scattered and difficult-to-maintain configuration files, supporting dynamic updates of configurations, and enabling new configurations to take effect without restarting the application program. When the configuration changes, Nacos will actively push notifications to the applications using this configuration, and the applications can perceive and load the new configuration in real time, greatly reducing the impact on the production environment. It can manage the historical versions of configurations, record information such as the time, content, and operator of each configuration change, facilitating rolling back to a specified historical version when needed, and providing a perfect permission control mechanism to ensure that only authorized users can access and modify specific configuration information, guaranteeing the security of configurations. In addition, it supports the client to listen for configurations. When the configuration changes, the client can receive notifications in a timely manner and perform corresponding processing.
[0057] Example illustration: In the field of healthcare, the medical platform application is divided into multiple independent modules, and each module can be developed, tested, and deployed independently. In this way, when updating, only the relevant modules need to be replaced without redeploying the entire system, thus achieving hot update. For example, the patient management module, doctor scheduling module, drug inventory management module, etc. can be developed and managed as independent modules respectively. Take the medical service platform as an example. Doctors and patients can communicate in real time through the online consultation platform. During the consultation process, if it is found that some functions of the platform need to be optimized or there are failures, the maintenance personnel can configure the files according to the optimization goals, then upload the configuration files to the server, and use the dynamic loading technology to obtain and load new modules or resources from the server during runtime, and then replace the old modules or resources.
[0058] In the financial field, take the banking system as an example. Monitor the changes in the monitoring rule files, configuration files, etc. Once a modification is detected, automatically load the new file content and apply it to the system. For example, monitor the interest rate calculation rule file in the banking system. When the interest rate rule in the file changes, automatically load the new rule without restarting the system. This avoids business interruptions caused by system restart, ensures the continuity of banking services, and improves customer satisfaction. Especially during the peak business period, hot loading can ensure the stable operation of the system without affecting customers' business handling.
[0059] S200. Perform pre-check for hot loading based on the relevant configuration information.
[0060] In this embodiment, after obtaining the relevant configuration information, pre-checks for hot loading will be performed first. The pre-checks include various aspects of information such as configuration check switches and whitelist lists, as well as security checks, which can effectively prevent the loading of illegal or incompatible jar packages and class files, ensuring the stability and security of the system.
[0061] S300. When the pre-check passes, obtain the list of files to be loaded, and perform hot loading operations on each file in the list of files to be loaded.
[0062] In this embodiment, by comparing and sorting the whitelist with the list of classes in the jar package, the required class files are accurately loaded in a specific order, avoiding the loading of unnecessary classes, and improving the resource utilization efficiency and loading pertinence.
[0063] S400. Determine whether the hot loading operation of each file is successful. If so, end the loading process; otherwise, perform a hot loading rollback operation and end the loading process.
[0064] In this embodiment, a mechanism for circularly loading class files is adopted. During the loading process, file annotation aliases and unloading injection information can be processed, and there is a rollback function in case of loading failure, which can ensure the reliability of loading. Information is recorded when the loading is successful, and at the same time, abnormal situations during the loading process can be effectively handled, reducing the risk of system failures caused by hot loading failures, and overall improving the stability and controllability of hot loading operations, providing strong support for the non-stop update and dynamic function expansion of Java applications.
[0065] In the embodiment of the present invention, first, obtain the relevant configuration information for file hot loading; then, based on the relevant configuration information, perform pre-checks for hot loading; after that, when the pre-check passes, obtain the list of files to be loaded, and perform hot loading operations on each file in the list of files to be loaded; finally, determine whether the hot loading operation of each file is successful. If so, end the loading process; otherwise, perform a hot loading rollback operation and end the loading process. The present invention can dynamically update configuration files, facilitating quick adjustment of hot loading-related settings according to different environments and requirements without redeploying the application. Through pre-checks, illegal or incompatible jar packages and class files can be effectively prevented from being loaded, ensuring the stability and security of the system. Moreover, it can achieve accurate loading of required class files in a specific order, avoiding the loading of unnecessary classes, improving resource utilization efficiency and loading pertinence. A mechanism for circularly loading class files is adopted. During the loading process, file annotation aliases and unloading injection information can be processed, and there is a rollback function in case of loading failure, which can ensure the reliability of loading. Information is recorded when the loading is successful, and at the same time, abnormal situations during the loading process can be effectively handled, reducing the risk of system failures caused by hot loading failures, and overall improving the stability and controllability of hot loading operations, providing strong support for the non-stop update and dynamic function expansion of Java applications.
[0066] In some embodiments, refer to Figure 3 , the step S200 specifically includes:
[0067] S210. Perform a security check for file hot loading based on the relevant configuration information;
[0068] S220. When the security check for file hot loading passes, perform a whitelist judgment for file hot loading based on the preset whitelist of the full class path of file hot loading.
[0069] In this embodiment, to ensure the security of file hot loading, first perform a security check for file hot loading, such as checks on the hot loading total switch, distributed lock, cache, file reading, etc., effectively preventing illegal or incompatible file loading, and ensuring the stability and security of the system. If the security check fails, the entire hot loading process ends. If the security check passes, further perform a whitelist judgment to effectively prevent the loading of illegal or incompatible jar packages and class files.
[0070] In some embodiments, the step S210 specifically includes:
[0071] Based on the switch information in the relevant configuration information, determine whether the file hot loading total switch is turned on;
[0072] When the file hot loading total switch is turned on, determine whether a distributed lock can be obtained;
[0073] When a distributed lock can be obtained, find the loading address through the cache and filter out the already loaded addresses;
[0074] After the filtering is completed, determine whether the file to be loaded can be read. If so, it means that the security check passes.
[0075] In this embodiment, first, it is judged whether the hot reload master switch is turned on. In the case of being turned off, it is impossible to enter the hot reload program logic. Therefore, when the hot reload master switch is not turned on, the entire hot reload process will end automatically. Specifically, there is no single configuration item named "hot reload master switch" in Nacos, but the function similar to the hot reload master switch can be achieved through configuration. For example, hot reload can be achieved by using Spring Cloud Alibaba Nacos Config or by using @NacosConfigurationProperties and @NacosPropertySource. When using Spring Cloud Alibaba Nacos Config to achieve hot reload, add the dependency of Spring Cloud Alibaba Nacos Config to the pom.xml file of the project, and then create a bootstrap.properties file in the resources directory to achieve the hot reload switch configuration. When using @NacosConfigurationProperties and @NacosPropertySource to achieve hot reload, the dependency of Spring Cloud Alibaba Nacos Config also needs to be added, and the basic information such as the Nacos server address is configured in the bootstrap.properties file.
[0076] When the hot reload master switch is turned on, obtain the distributed lock check to ensure that only one thread on a machine can perform the hot reload program. For example, use the local IP address as the key. If the lock cannot be obtained, the hot reload will not be performed. Specifically, the distributed lock is a distributed lock mechanism used to coordinate the access to shared resources in a distributed system to ensure that only one process can hold the lock at the same time, thus avoiding data competition and inconsistent problems. Specifically, it can be implemented through a database or a cache system. For example, a specific table can be created. When operating on certain resources, first insert a record corresponding to the resource into the table for "locking", and delete the record for "unlocking" after the operation is completed, or use the SETNX (Set if Not eXists) command of Redis. This command can only be set successfully and return 1 when the key does not exist, otherwise it returns 0. Through this feature, the effect similar to a mutex lock can be achieved.
[0077] After the distributed lock verification is completed, look up the loaded address through the cache. If the address has been loaded, it will not be loaded again. The cache is a commonly used technical means to improve the performance and response speed of the system. By looking up the loaded address through the cache, the number of requests to the backend service can be effectively reduced, the pressure on the server can be alleviated, and the user experience can be improved.
[0078] After the filtering is completed, then determine whether the file to be loaded can be read. If the file reading fails, the loading process will be directly ended.
[0079] In some embodiments, the step S220 specifically includes:
[0080] When the security verification of the file hot loading passes, determine whether the file type of the file to be loaded meets the requirements;
[0081] When the file type of the file to be loaded meets the requirements, determine whether the file to be loaded is in the preset class full path white list for file hot loading. If so, it means the verification passes.
[0082] In this embodiment, first, the type of the file is judged. If the file type does not meet the requirements, it will be directly filtered. Exemplarily, since the.class file is the bytecode file generated after the Java compiler compiles the.java source file, therefore, the file must be a file ending with the.class file to meet the requirements. After the file type verification passes, the white list verification is performed. The white list filtering can be performed through the preset class full path white list. Specifically, the class full path white list is a security mechanism used to limit the path range of classes that the program can access or execute. In Java development, the class full path white list can be set by using a security manager, a custom class loader, using a third-party library, using Spring Security, etc. In this embodiment, the white list is obtained through the configuration center and is generally configured as multiple class full path lists, such as: com.xxx.A, com.xxx.B..., and the loading class path list of the white list has a loading order. At this time, it is necessary to load A first and then B.
[0083] In some embodiments, please refer to Figure 4 , the step S300 specifically includes:
[0084] S310. When the pre-verification passes, obtain the list of files to be loaded;
[0085] S320. Based on the preset order of the class full path white list files, reorder the files in the prime number list of files to be loaded to obtain the sorted list of files to be loaded;
[0086] S330. Based on the sorted list of loaded files, perform a hot loading operation on each file in the loaded file list.
[0087] In this embodiment, when reading the jar package and traversing the class files, it is impossible to guarantee the reading order (when traversing the jar classes, class B may be ranked before class A). Therefore, the class files read from the jar package cannot be used as the loading order. Here, first, the class paths in the whitelist are filtered with the classes in the jar package to filter out the loadable classes. Then, the whitelist is traversed and re-sorted in the order of the whitelist to obtain the sorted loading list. Finally, the hot loading operation is performed according to the sorted loading list. The present invention compares and sorts the whitelist with the class list in the jar package to achieve precise loading of the required class files in a specific order, avoiding the loading of unnecessary classes, and improving the resource utilization efficiency and loading pertinence.
[0088] In some embodiments, please refer to Figure 5 , the step S400 specifically includes:
[0089] S410. Determine whether the currently loaded file is successfully loaded. If so, record the loaded information. If the currently loaded file is not successfully loaded, roll back the loaded file to the version before loading and end the loading process.
[0090] S420. Determine whether all files have been loaded. If so, end the loading process; otherwise, continue to load the next file.
[0091] In this embodiment, file processing before loading is also required before performing file hot loading. Specifically, when implementing, if it is a newly loaded class, the basic information of the class before being overwritten, including the class name, class object, etc., can be tried to be obtained, which can be used to roll back the version. If it is a class managed by Spring, it is first unregistered; otherwise, an error will occur during subsequent re-management injection.
[0092] After the file processing before loading is completed, the file loading operation starts. Then, it is determined whether the loading is completed. If so, the loaded file information is recorded. Among them, recording the loaded file information is crucial for tasks such as debugging, performance optimization, and security auditing. Specifically, when implementing, the following several methods can be used to record the loaded file information:
[0093] One. Use the browser developer tools
[0094] Network Panel: In browser developer tools such as Chrome DevTools, after opening the Network panel and reloading the page, all loaded resource files can be viewed, including HTML, CSS, JavaScript, images, etc. This information is displayed in the Network panel and can be manually copied or exported.
[0095] Performance Panel: Detailed resource loading information can be obtained through the Performance panel, such as page loading time, start loading time and completion time of each resource, etc. Similarly, this information can also be manually copied or exported.
[0096] II. Using Programming Methods
[0097] Network API in JavaScript: By using JavaScript's Network API, such as the Performance API and Resource Timing API, scripts can be written to automatically collect resource loading information. For example, use performance.getEntriesByType('resource') to obtain information about all resource loading entries and record them in a log file.
[0098] MutationObserver to Monitor DOM Element Changes: By using MutationObserver to monitor changes in the DOM tree, when new nodes are added, dynamically loaded resources such as asynchronously loaded scripts and style sheets can be detected. The detected resource information can be recorded in the log.
[0099] Intercept XMLHttpRequest and Fetch API: By intercepting requests of XMLHttpRequest and Fetch API, requests for dynamically loaded resources can be captured to understand which files are loaded in these ways. Record the intercepted information in the log.
[0100] III. View System Logs or Debug Output
[0101] Visual Studio Debugger: In the Visual Studio debugger, when starting the application, information about various loaded executable files and dynamic link libraries (DLLs) will be displayed, as well as whether the PDB file containing debug symbol information has been found. This information can be directly copied from the output window of the debugger and saved to a log file.
[0102] Logs of the application itself: Some applications record information about loaded files in a log file during runtime. By configuring the application's logging function, it is ensured that all loaded file information is recorded.
[0103] IV. Using third - party tools
[0104] Network packet capture tools such as Fiddler: Network packet capture tools such as Fiddler can capture the network traffic between the computer and the server, thereby analyzing information such as which files are loaded, the request time, and the response status. This information can be directly exported as a log file or further processed.
[0105] V. Writing custom scripts or programs
[0106] Python scripts: Using Python's requests library or other HTTP client libraries, scripts can be written to send HTTP requests and record response information. For example, traverse all pages of a website and record the resource information loaded on each page.
[0107] Node.js scripts: Using Node.js' http or https modules, scripts can be written to send HTTP requests and record response information. For example, traverse all pages of a website and record the resource information loaded on each page.
[0108] VI. Using logging frameworks
[0109] Logging frameworks such as Log4j and SLF4J: In Java applications, logging frameworks such as Log4j and SLF4J can be used to record information about loaded files. By configuring the logging framework, resource loading information can be output to a log file.
[0110] Logging frameworks such as Logback and NLog: In.NET applications, logging frameworks such as Logback and NLog can be used to record information about loaded files. By configuring the logging framework, resource loading information can be output to a log file.
[0111] Furthermore, when the loading is unsuccessful, the present invention adopts a fallback mechanism to ensure the reliability of loading. Loading fallback means that in a program or system, when attempting to load a certain resource, file, or perform a certain operation, if an error or problem is encountered, the system will automatically fallback to the previous state to avoid data loss or system crash.
[0112] In some embodiments, step S420 specifically includes:
[0113] Determine whether an error is captured during the loading process;
[0114] When no error is captured during the loading process, it is judged whether all class records of the loaded classes are normally recorded;
[0115] When all class records of the loaded classes are normally recorded, it is judged whether the rollback version operation has been triggered. If not, it is determined that all file loadings are completed.
[0116] In this embodiment, the judgment conditions for whether the loading is completed include: no error is captured during the loading process, all class records of the loaded classes can be normally recorded, and the rollback version operation is not triggered. The present invention adopts a cyclic class file loading mechanism, which can process file annotation aliases and uninstall injection information during the loading process, and has a rollback function when the loading fails, which can ensure the reliability of the loading, record information when the loading is successful, and can effectively handle abnormal situations during the loading process, reduce the risk of system failures caused by hot loading failures, and overall improve the stability and controllability of the hot loading operation, providing strong support for the non-stop update and dynamic function expansion of Java applications.
[0117] The technical solution provided by the present invention is as follows: First, obtain the relevant configuration information for file hot loading; then, based on the relevant configuration information, perform pre-checks for hot loading; after that, when the pre-checks pass, obtain the list of files to be loaded and perform hot loading operations on each file in the list of files to be loaded; finally, judge whether the hot loading operations of each file are successful. If so, end the loading process; otherwise, perform a hot loading rollback operation and end the loading process. The present invention can dynamically update configuration files, facilitating quick adjustment of hot loading-related settings according to different environments and requirements without redeploying the application. Through pre-checks, it can effectively prevent the loading of illegal or incompatible jar packages and class files, ensuring system stability and security, and can achieve precise loading of required class files in a specific order, avoiding the loading of unnecessary classes, improving resource utilization efficiency and loading pertinence. Adopting a cyclic class file loading mechanism, it can process file annotation aliases and uninstall injection information during the loading process, and has a rollback function when the loading fails, which can ensure the reliability of the loading, record information when the loading is successful, and can effectively handle abnormal situations during the loading process, reduce the risk of system failures caused by hot loading failures, and overall improve the stability and controllability of the hot loading operation, providing strong support for the non-stop update and dynamic function expansion of Java applications.
[0118] Another embodiment of the present invention provides a file hot loading device. Please refer to Figure 6 , the file hot loading device includes an information acquisition module 11, a pre-check module 12, a file acquisition module 13, and a judgment module 14.
[0119] The information acquisition module 11 is used to acquire the relevant configuration information for file hot loading.
[0120] The pre-check module 12 is used to perform pre-check for hot loading based on the relevant configuration information.
[0121] The file acquisition module 13 is used to obtain the list of files to be loaded and perform hot loading operations on each file in the list of files to be loaded when the pre-check passes.
[0122] The judgment module 14 is used to judge whether the hot loading operation of each file is successful. If so, the loading process ends; otherwise, a hot loading rollback operation is executed and the loading process ends.
[0123] In some embodiments, the pre-check module 12 specifically includes:
[0124] The security check unit is used to perform security checks on file hot loading based on the relevant configuration information;
[0125] The whitelist check unit is used to perform whitelist judgment on file hot loading based on the preset full class path whitelist of file hot loading when the security check of file hot loading passes.
[0126] In some embodiments, the security check unit is specifically used for:
[0127] Based on the switch information in the relevant configuration information, judge whether the overall switch of file hot loading is turned on;
[0128] When the overall switch of file hot loading is turned on, judge whether a distributed lock can be obtained;
[0129] When a distributed lock can be obtained, find the loading address through the cache and filter out the addresses that have been loaded;
[0130] After the filtering is completed, judge whether the file to be loaded can be read. If so, it means that the security check passes.
[0131] In some embodiments, the whitelist check unit is specifically used for:
[0132] When the security check of file hot loading passes, judge whether the file type of the file to be loaded meets the requirements;
[0133] When the file type of the file to be loaded meets the requirements, judge whether the file to be loaded is in the preset full class path whitelist of file hot loading. If so, it means that the check passes.
[0134] In some embodiments, the file acquisition module 13 specifically includes:
[0135] The file list acquisition unit is used to obtain the list of files to be loaded when the pre-check passes;
[0136] A sorting unit for re-sorting the files in the prime number loading file list based on the order of a preset class full path whitelist file to obtain a sorted loading file list;
[0137] A loading unit for performing a hot loading operation on each file in the loading file list based on the sorted loading file list.
[0138] In some embodiments, the judgment module 14 specifically includes:
[0139] A first loading judgment unit for judging whether the currently loaded file is successfully loaded. If so, record the loaded information. If the currently loaded file is not successfully loaded, roll back the loaded file to the version before loading and end the loading process;
[0140] A second loading judgment unit for judging whether all files have been loaded. If so, end the loading process. Otherwise, continue to load the next file.
[0141] In some embodiments, the second loading judgment unit is specifically used for:
[0142] Judging whether an error is captured during the loading process;
[0143] When no error is captured during the loading process, judging whether all class records of the loaded classes are normally recorded;
[0144] When all class records of the loaded classes are normally recorded, judging whether a rollback version operation has been triggered. If not, it is determined that all files have been loaded.
[0145] In an embodiment of the present invention, first, relevant configuration information for file hot loading is obtained; then, based on the relevant configuration information, pre-check for hot loading is performed; after that, when the pre-check passes, a list of files to be loaded is obtained, and hot loading operations are performed on each file in the list of files to be loaded; finally, it is determined whether the hot loading operations of each file are successful. If so, the loading process ends; otherwise, a hot loading rollback operation is executed and the loading process ends. The present invention can dynamically update configuration files, facilitating quick adjustment of hot loading related settings according to different environments and requirements without redeploying the application. Through pre-check, illegal or incompatible jar packages and class files can be effectively prevented from being loaded, ensuring system stability and security. Moreover, it can achieve precise loading of required class files in a specific order, avoiding the loading of unnecessary classes, improving resource utilization efficiency and loading pertinence. By adopting a mechanism of circularly loading class files, file annotation aliases and unloading injection information can be processed during the loading process, and there is a rollback function in case of loading failure, ensuring the reliability of loading. When successfully loaded, information is recorded, and at the same time, abnormal situations during the loading process can be effectively handled, reducing the risk of system failures caused by hot loading failures, overall enhancing the stability and controllability of hot loading operations, and providing strong support for the non-stop update and dynamic function expansion of Java applications.
[0146] Those of ordinary skill in the art can understand that all or part of the processes of implementing the methods in the above embodiments can be completed by instructing relevant hardware through computer-readable instructions. These computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a magnetic disk, an optical disk, a read-only memory (ROM), etc., or a random access memory (RAM), etc.
[0147] It should be understood that although the steps in the flowchart of the accompanying drawings are shown in sequence according to the indication of the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear indication in this article, the execution of these steps is not strictly limited in order, and they can be executed in other orders. Moreover, at least some of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed alternately or in turn with at least a part of other steps or sub-steps or stages of other steps.
[0148] In one embodiment, a computer device is provided. This computer device can be a server, and its internal structural diagram can be as Figure 7As shown in the figure. The computer device includes a processor, a memory, a network interface, and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external client through a network connection. When the computer program is executed by the processor, it realizes the functions or steps on the server side of a file hot loading method.
[0149] In one embodiment, a computer device is provided. The computer device can be a client, and its internal structure diagram can be as Figure 8 As shown in the figure. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server through a network connection. When the computer program is executed by the processor, it realizes the functions or steps on the client side of a file hot loading method.
[0150] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the following steps are implemented:
[0151] Obtain the relevant configuration information for file hot loading;
[0152] Based on the relevant configuration information, perform pre-check for hot loading;
[0153] When the pre-check passes, obtain the list of files to be loaded, and perform hot loading operations on each file in the list of files to be loaded;
[0154] Judge whether the hot loading operation of each file is successful. If so, end the loading process; otherwise, execute the hot loading rollback operation and end the loading process.
[0155] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by the processor, the following steps are implemented:
[0156] Obtain the relevant configuration information for file hot loading;
[0157] Perform pre-check for hot loading based on the relevant configuration information;
[0158] When the pre-check passes, obtain the list of files to be loaded and perform hot loading operations on each file in the list of files to be loaded;
[0159] Determine whether the hot loading operations of all files are successful. If so, end the loading process; otherwise, perform a hot loading rollback operation and end the loading process.
[0160] It should be noted that the functions or steps that can be achieved by the above-mentioned computer-readable storage medium or computer device can refer to the relevant descriptions on the server side and the client side in the foregoing method embodiments respectively. To avoid repetition, they will not be described in detail here.
[0161] Those of ordinary skill in the art can understand that all or part of the processes of implementing the methods in the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the above method embodiments. Among them, any reference to the memory, storage, database or other media used in the various embodiments provided in the present application can include non-volatile and / or volatile memories. The non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. The volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and Rambus dynamic RAM (RDRAM), etc.
[0162] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above-mentioned division of each functional unit and module is used as an example. In actual applications, the above functions can be allocated to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0163] In summary, for the file hot loading method, device, computer device and storage medium provided by the present invention, first, relevant configuration information for file hot loading is obtained; then, based on the relevant configuration information, pre-check for hot loading is performed; after that, when the pre-check passes, a list of files to be loaded is obtained, and hot loading operations are performed on each file in the list of files to be loaded; finally, it is determined whether the hot loading operations of each file are successful. If so, the loading process ends; otherwise, a hot loading rollback operation is executed and the loading process ends. The present invention can dynamically update configuration files, facilitating quick adjustment of hot loading related settings according to different environments and requirements without redeploying the application. Through pre-check, illegal or incompatible jar packages and class files can be effectively prevented from being loaded, ensuring system stability and security. Moreover, it can accurately load required class files in a specific order, avoiding the loading of unnecessary classes, improving resource utilization efficiency and loading pertinence. By adopting a mechanism of circularly loading class files, file annotation aliases and unloading injection information can be processed during the loading process, and there is a rollback function in case of loading failure, ensuring the reliability of loading. Information is recorded when the loading is successful, and at the same time, abnormal situations during the loading process can be effectively handled, reducing the risk of system failures caused by hot loading failures, and overall improving the stability and controllability of hot loading operations, providing strong support for the non-stop update and dynamic function expansion of Java applications.
[0164] It should be noted that in the embodiments of the present application, if there are software tools or components of other companies, they are only used for example introduction and do not represent actual use.
[0165] The specific implementation manners of the present invention described above do not constitute a limitation to the protection scope of the present invention. Any other corresponding changes and deformations made according to the technical concept of the present invention should be included in the protection scope of the claims of the present invention.
Claims
1. A file hot loading method, characterized in that It includes the following steps: Obtain relevant configuration information for file hot loading; Based on the relevant configuration information, perform pre-check for hot loading; When the pre-check passes, obtain the list of files to be loaded, and perform hot loading operations on each file in the list of files to be loaded; Judge whether the hot loading operations of all files are successful. If so, end the loading process. Otherwise, perform a hot loading rollback operation and end the loading process.
2. The file hot reload method according to claim 1, characterized in that The performing pre-check for hot loading based on the relevant configuration information includes: Based on the relevant configuration information, perform security check for file hot loading; When the security check for file hot loading passes, based on the preset whitelist of full class paths for file hot loading, perform whitelist judgment for file hot loading.
3. The file hot loading method according to claim 2, wherein The performing security check for file hot loading based on the relevant configuration information includes: Based on the switch information in the relevant configuration information, judge whether the overall switch for file hot loading is turned on; When the overall switch for file hot loading is turned on, judge whether a distributed lock can be obtained; When a distributed lock can be obtained, find the loading address through the cache and filter out the addresses that have been loaded; After the filtering is completed, judge whether the file to be loaded can be read. If so, it means that the security check passes.
4. The file hot loading method according to claim 2, wherein The performing whitelist judgment for file hot loading based on the preset whitelist of full class paths for file hot loading when the security check for file hot loading passes includes: When the security check for file hot loading passes, judge whether the file type of the file to be loaded meets the requirements; When the file type of the file to be loaded meets the requirements, judge whether the file to be loaded is in the preset whitelist of full class paths for file hot loading. If so, it means that the check passes.
5. The file hot loading method according to claim 1, characterized in that The obtaining the list of files to be loaded and performing hot loading operations on each file in the list of files to be loaded when the pre-check passes includes: When the pre-check passes, obtain the list of files to be loaded; Based on the preset order of files in the whitelist of full class paths, reorder the files in the list of files to be loaded to obtain the sorted list of files to be loaded; Based on the sorted list of files to be loaded, perform hot loading operations on each file in the list of files to be loaded.
6. The file hot loading method according to claim 1, wherein The judging whether the hot loading operations of all files are successful. If so, end the loading process. Otherwise, perform a hot loading rollback operation and end the loading process includes: Judge whether the currently loaded file is loaded successfully. If so, record the loaded information. If the currently loaded file is not loaded successfully, roll back the loaded file to the version before loading and end the loading process; Judge whether all files have been loaded. If so, end the loading process. Otherwise, continue to load the next file.
7. The file hot loading method according to claim 6, wherein The judging whether all files have been loaded includes: Judge whether an error is captured during the loading process; When no error is captured during the loading process, judge whether all class records of the loaded classes are normally recorded; When all class records of the loaded classes are normally recorded, judge whether the rollback version operation has been triggered. If not, it is determined that all files have been loaded.
8. A file hot loading device, characterized in that, It includes: An information acquisition module, configured to acquire relevant configuration information for file hot reloading; A pre-check module, configured to perform pre-check for hot reloading based on the relevant configuration information; A file acquisition module, configured to acquire a list of files to be loaded and perform hot reloading operations on each file in the list of files to be loaded when the pre-check passes; A judgment module, configured to judge whether the hot reloading operations of all files are successful. If so, the loading process is ended. Otherwise, a hot reloading rollback operation is performed and the loading process is ended.
9. A computer device, characterized in that, It includes a memory and a processor. Computer-readable instructions are stored in the memory. When the processor executes the computer-readable instructions, the steps of the file hot reloading method described in any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that, Computer-readable instructions are stored on the computer-readable storage medium. When the computer-readable instructions are executed by the processor, the steps of the file hot reloading method described in any one of claims 1 to 7 are implemented.