CN116009906A - Java-based hot updating method and device - Google Patents

Java-based hot updating method and device Download PDF

Info

Publication number
CN116009906A
CN116009906A CN202211116398.6A CN202211116398A CN116009906A CN 116009906 A CN116009906 A CN 116009906A CN 202211116398 A CN202211116398 A CN 202211116398A CN 116009906 A CN116009906 A CN 116009906A
Authority
CN
China
Prior art keywords
java
file
objects
hot update
files
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211116398.6A
Other languages
Chinese (zh)
Inventor
张伟伟
袁冠鹏
李建良
何雨泉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Yunyou Interactive Network Technology Co ltd
Online Tuyoo Beijing Technology Co ltd
Original Assignee
Beijing Yunyou Interactive Network Technology Co ltd
Online Tuyoo Beijing Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Yunyou Interactive Network Technology Co ltd, Online Tuyoo Beijing Technology Co ltd filed Critical Beijing Yunyou Interactive Network Technology Co ltd
Priority to CN202211116398.6A priority Critical patent/CN116009906A/en
Publication of CN116009906A publication Critical patent/CN116009906A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Stored Programmes (AREA)

Abstract

In the embodiment of the application, when Java-based hot update is performed, updated Java files are acquired in real time and are dynamically compiled into byte code files; all hot updating byte code files are further loaded through a custom class loader; finally, all old objects are replaced instantaneously and dynamically by means of Copy-On-Write. The embodiment of the application does not introduce a third party framework and is realized by completely utilizing the characteristics of the JDK; and because the modification of the byte code is not carried out and a dynamic agent is not introduced, the proposal perfectly supports the output of reflection and abnormal stacks and has higher performance, can conveniently inquire various running data in a positioning system and well supports the positioning and solving of system bug.

Description

Java-based hot updating method and device
Technical Field
The present application relates to the field of computer technologies, and in particular, to a Java-based thermal updating method, apparatus, computing device, and computer readable storage medium.
Background
In the prior art, the server hot update technology refers to a technology for implementing code update without interrupting service. After JDK1.5, a proxy mechanism for Java Agent is provided, and the flow of hot update is approximately: configuring jdk-java agent starting parameters; using Instumentation API to modify the loaded class; dynamically adding a layer of agent at each of the Method-Call and the Field-Access places, and dynamically generating an agent implementation class; by monitoring a certain path or Jar, a brand new implementation class is directly loaded as a proxied object for each modified class. However, the internal implementation of the method is complex, and the support for reflection and abnormal stacks is not friendly, so that the on-line service is inconvenient to debug and repair.
Disclosure of Invention
In view of the foregoing, the present application provides a Java-based thermal updating method, apparatus, computing device, and computer-readable storage medium, which solve the technical drawbacks in the prior art.
According to a first aspect of an embodiment of the present application, there is provided a Java-based hot update method, including:
monitoring Java file changes under a specified directory in real time;
when the Java file is found to change, compiling the changed Java file in real time during operation to obtain a corresponding byte code file;
all objects are instantiated and the replacement of the objects is completed by the custom class loader loading all hot update bytecode files.
According to a second aspect of embodiments of the present application, there is provided a Java-based hot-update apparatus, including:
the monitoring unit is used for monitoring Java file changes under the appointed directory in real time;
the dynamic compiling unit is used for compiling the changed Java file in real time during running to obtain a corresponding byte code file when the Java file is found to be changed;
and the updating unit is used for loading all hot updating byte code files through the custom class loader, instantiating all objects and completing the replacement of the objects.
According to a third aspect of embodiments of the present application, there is provided a computing device comprising a memory, a processor and computer instructions stored on the memory and executable on the processor, the processor implementing the steps of the aforementioned method when executing the instructions.
According to a fourth aspect of embodiments of the present application, there is provided a computer readable storage medium storing computer instructions which, when executed by a processor, implement the steps of the aforementioned method.
By the method and the device in the embodiment of the application, when in hot update, all byte code files are uniformly loaded into a new class loader after the updated Java files are compiled, and then the old object instance is replaced by the new object instance in a whole instant manner, so that a simple and high-performance hot update scheme is realized. And because the modification of the byte code is not carried out and a dynamic agent is not introduced, the proposal perfectly supports the output of reflection and abnormal stacks and higher performance, can conveniently inquire various running data in a positioning system, and well supports the positioning and solving of system bug.
Drawings
FIG. 1 is a block diagram of a computing device provided by an embodiment of the present application;
FIG. 2 is a flow chart of a Java-based hot update method according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of a Java-based thermal updating apparatus according to an embodiment of the present application.
Detailed Description
In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present application. This application is, however, susceptible of embodiment in many other ways than those herein described and similar generalizations can be made by those skilled in the art without departing from the spirit of the application and the application is therefore not limited to the specific embodiments disclosed below.
The terminology used in one or more embodiments of the application is for the purpose of describing particular embodiments only and is not intended to be limiting of one or more embodiments of the application. As used in this application in one or more embodiments and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used in one or more embodiments of the present application refers to and encompasses any or all possible combinations of one or more of the associated listed items.
It should be understood that, although the terms first, second, etc. may be used in one or more embodiments of the present application to describe various information, these information should not be limited to these terms. These terms are only used to distinguish one type of information from another. For example, a first may also be referred to as a second, and similarly, a second may also be referred to as a first, without departing from the scope of one or more embodiments of the present application. The word "if" as used herein may be interpreted as "responsive to a determination" depending on the context.
FIG. 1 illustrates a block diagram of a computing device 100, according to an embodiment of the present application. The components of the computing device 100 include, but are not limited to, a memory 110 and a processor 120. Processor 120 is coupled to memory 110 via bus 130 and database 150 is used to store data.
Computing device 100 also includes access device 140, access device 140 enabling computing device 100 to communicate via one or more networks 160. Examples of such networks include the Public Switched Telephone Network (PSTN), a Local Area Network (LAN), a Wide Area Network (WAN), a Personal Area Network (PAN), or a combination of communication networks such as the internet. The access device 140 may include one or more of any type of network interface, wired or wireless (e.g., a Network Interface Card (NIC)), such as an IEEE802.11 Wireless Local Area Network (WLAN) wireless interface, a worldwide interoperability for microwave access (Wi-MAX) interface, an ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a bluetooth interface, a Near Field Communication (NFC) interface, and so forth.
In one embodiment of the present application, the above-described components of computing device 100, as well as other components not shown in FIG. 1, may also be connected to each other, such as by a bus. It should be understood that the block diagram of the computing device shown in FIG. 1 is for exemplary purposes only and is not intended to limit the scope of the present application. Those skilled in the art may add or replace other components as desired.
Computing device 100 may be any type of stationary or mobile computing device including a mobile computer or mobile computing device (e.g., tablet, personal digital assistant, laptop, notebook, netbook, etc.), mobile phone (e.g., smart phone), wearable computing device (e.g., smart watch, smart glasses, etc.), or other type of mobile device, or a stationary computing device such as a desktop computer or PC. Computing device 100 may also be a mobile or stationary server.
The processor 120 of fig. 1 of the specification may perform the steps of a Java-based hot update method shown in fig. 2, including steps 202 to 206:
step 202: and monitoring Java file changes under the appointed directory in real time.
In one possible implementation, the server monitors Java files under a specified directory through a monitoring thread, and notifies the server when a change occurs in a thermally updated Java file under the directory.
Further, under the specified directory, the Java file that can be thermally updated is identified by a specific file suffix, for example, a hot fix suffix is added to the file name of the Java file that needs to be thermally updated: for example
XXXA_hotfix.java;
XXXB_hotfix.java;
XXXC_hotfix.java;
Further, after the client finishes the development of the hot update Java file, the hot update Java file is uploaded to the appointed directory of the server.
Step 204: when the Java file is found to change, the changed Java file is compiled in real time during running, and a byte code file is obtained.
In the step, when the monitoring thread of the server monitors that the Java file changes, the changing hot update Java file is compiled into a class file by the Java compiler in the running process.
The Java compiler is a dynamic compiling function provided by the version JDK1.6, and can compile Java files into byte code files after acquiring paths of the Java files in the running process, wherein the following codes are as follows:
JavaCompiler compiler=ToolProvider.getSystemJavaCompiler();
int result=compiler.run(null,null,null,"/XXX_hotfix.java");
for example, in one possible implementation, when the server finds that 3 Java files xxxa_hotfix, xxxb_hotfix, xxxc_hotfix, java are newly added to the specified directory, the corresponding byte codes xxxa_hotfix, class, xxxb_hotfix, class are compiled by using a JavaCompiler tool.
In another possible implementation, when the server finds that the xxxc_hotfix.java file in the specified directory is updated, the java compiler tool is used to compile the file to obtain the corresponding byte code xxxb_hotfix.class, and other byte code files remain unchanged.
Step 206: all objects are instantiated and the replacement of the objects is completed by the custom class loader loading all hot update bytecode files.
In the step, when the server monitors the change of the java file, after compiling the changed java file to obtain the byte code file, loading all existing hot update byte code files through a custom class loader, and completing the instantiation of all objects in the byte code file.
For example, in one possible implementation, when the server first performs a hot update, it finds that the specified directory is newly added with 3 Java files xxxa_hotfix, xxxb_hotfix, xxxc_hotfix, java, and compiles using a JavaCompiler tool to obtain corresponding byte codes xxxa_hotfix, class, xxxb_hotfix, class, and xxxc_hotfix, class, respectively; further, loading all hot update bytecode files with custom class loaders includes: XXXA_hotfix.class, XXXB_hotfix.class and XXXC_hotfix.class.
In one possible implementation, when the server finds that the XXXC_hotfix.java file in the specified directory is updated in the subsequent monitoring process, the Java compiler tool is used to compile the file to obtain the corresponding byte code XXXB_hotfix.class, and other byte code files remain unchanged. At this time, all hot update bytecode files are loaded by the custom class loader, including: XXXA_hotfix.class, XXXB_hotfix.class and XXXC_hotfix.class, where only XXXB_hotfix.class changes, XXXA_hotfix.class and XXXC_hotfix.class do not change.
I.e. once the Java file is monitored to change, the changed Java file is compiled, and all hot update bytecode files are loaded through a custom class loader.
Further, all old objects are replaced with newly instantiated objects. Instantaneous dynamic replacement of all old objects by means of Copy-On-Write while object replacement is performed;
specifically, the container is replaced instantaneously and dynamically in a Copy-On-Write manner based On the characteristic of volatile in Java language. Where volatile is a lightweight synchronization mechanism provided by Java virtual machines, it is commonly used to ensure that other threads are notified of variable update operations.
After the first instantiation of a hot update object, all hot update instantiations have a container Map < Class <? extends APIJScript > within APIJScript > MapA, reference ref with the volatile attribute points to the MapA container; when the hot update file is updated, all hot update instantiations objects after the next instantiation exist in the container Map < Class <? extends APIJScript >, APIJScript > MapB, at which point the reference ref with the volatile property is made to point to the MapB container, thus completing the replacement of all hot update instance objects.
Further, a new hot update object instance is associated in an interface mode, and the call of the hot update object is completed.
For a certain hot update object which needs to be called externally, the same interface is realized before and after the update, such as
public class HotfixAImpl implements IHotfixA
{...}
When an external object calls a hot update object, an interface calling mode is adopted, so that decoupling is realized, dynamic update is convenient, and the original business logic is not influenced, for example:
HotfixAImpl impl=JScriptQuery.getScript(IHotfixA.class);
in the above embodiment of the present application, when performing Java-based hot update, updated Java files are obtained in real time, and are dynamically compiled into byte code files; all hot updating byte code files are further loaded through a custom class loader, wherein the hot updating byte code files comprise updated and un-updated hot updating byte codes; finally, all old objects are replaced instantaneously and dynamically in a Copy-On-Write mode through the characteristic of the volatile of Java language. In the embodiment of the application, all byte code files are uniformly loaded into a new class loader after the updated Java files are compiled, so that the old object instance is replaced by the new object instance entirely, and a simple and high-performance hot updating scheme is realized. The scheme does not introduce a third party framework, is realized by completely utilizing the characteristics of the JDK, and is completely and independently controllable; and because the modification of the byte code is not carried out and a dynamic agent is not introduced, the proposal perfectly supports the output of reflection and abnormal stacks and has higher performance, can conveniently inquire various running data in a positioning system and well supports the positioning and solving of system bug.
Corresponding to the above method embodiments, the present application further provides an embodiment of a Java-based thermal updating apparatus, and fig. 3 shows a schematic structural diagram of a Java-based thermal updating apparatus according to an embodiment of the present application, including:
the monitoring unit is used for monitoring Java file changes under the appointed directory in real time;
the dynamic compiling unit is used for compiling the changed Java file in real time during running to obtain a corresponding byte code file when the Java file is found to be changed;
and the updating unit is used for loading all hot updating byte code files through the custom class loader, instantiating all objects and completing the replacement of the objects.
The above is a schematic scheme of the related apparatus of this embodiment. It should be noted that, the technical solution of the Java-based thermal updating apparatus and the technical solution of the Java-based thermal updating method belong to the same concept, and details of the technical solution of the Java-based thermal updating apparatus, which are not described in detail, can be referred to the description of the technical solution of the Java-based thermal updating method.
An embodiment of the present application also provides a computing device including a memory, a processor, and computer instructions stored on the memory and executable on the processor, which when executed by the processor implements the steps of the Java-based thermal updating method described above.
An embodiment of the present application also provides a computer-readable storage medium storing computer instructions that, when executed by a processor, implement the steps of the Java-based thermal updating method as described above.
The above is an exemplary version of a computer-readable storage medium of the present embodiment. It should be noted that, the technical solution of the storage medium and the technical solution of the Java-based thermal updating method belong to the same concept, and details of the technical solution of the storage medium, which are not described in detail, can be referred to the description of the technical solution of the Java-based thermal updating method.
The foregoing describes specific embodiments of the present application. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims can be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
The computer instructions include computer program code that may be in source code form, object code form, executable file or some intermediate form, etc. The computer readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a U disk, a removable hard disk, a magnetic disk, an optical disk, a computer Memory, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), an electrical carrier signal, a telecommunications signal, a software distribution medium, and so forth. It should be noted that the computer readable medium contains content that can be appropriately scaled according to the requirements of jurisdictions in which such content is subject to legislation and patent practice, such as in certain jurisdictions in which such content is subject to legislation and patent practice, the computer readable medium does not include electrical carrier signals and telecommunication signals.
It should be noted that, for the sake of simplicity of description, the foregoing method embodiments are all expressed as a series of combinations of actions, but it should be understood by those skilled in the art that the present application is not limited by the order of actions described, as some steps may be performed in other order or simultaneously in accordance with the present application. Further, those skilled in the art will also appreciate that the embodiments described in the specification are all preferred embodiments, and that the acts and modules referred to are not necessarily all necessary for the present application.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and for parts of one embodiment that are not described in detail, reference may be made to the related descriptions of other embodiments.
The above-disclosed preferred embodiments of the present application are provided only as an aid to the elucidation of the present application. Alternative embodiments are not intended to be exhaustive or to limit the invention to the precise form disclosed. Obviously, many modifications and variations are possible in light of the teaching of this application. The embodiments were chosen and described in order to best explain the principles of the invention and the practical application, to thereby enable others skilled in the art to best understand and utilize the invention. This application is to be limited only by the claims and the full scope and equivalents thereof.

Claims (9)

1. A Java-based hot update method, comprising:
monitoring Java file changes under a specified directory in real time;
when the Java file is found to change, compiling the changed Java file in real time during operation to obtain a corresponding byte code file;
all objects are instantiated and the replacement of the objects is completed by the custom class loader loading all hot update bytecode files.
2. The method of claim 1, wherein the thermally updateable Java file is identified by a specific file suffix under a specified directory.
3. The method of claim 2, wherein compiling the changed Java file in real-time at runtime to obtain the corresponding bytecode file comprises:
the changed Java files are compiled into class files by the Java compiler at runtime.
4. The method of claim 1, wherein instantiating all the objects and completing replacement of the objects comprises:
all old objects are replaced instantaneously and dynamically by means of Copy-On-Write when object replacement is performed.
5. The method of claim 4, wherein instantaneously and dynamically replacing all old objects by means of Copy-On-Write comprises:
saving a previous hot update instantiation object with a first container, pointing a reference ref having a volt attribute to the first container; when the hot update file is updated, the hot update instantiation object after the next instantiation exists in the second container, so that the reference ref with the attribute of volt points to the second container and releases the first container, and replacement of all the hot update instantiation objects is completed.
6. The method of claim 1, wherein new hot update objects are associated by way of an interface, the hot update objects being invoked externally implementing the same interface both before and after the update.
7. A Java-based thermal updating apparatus, comprising:
the monitoring unit is used for monitoring Java file changes under the appointed directory in real time;
the dynamic compiling unit is used for compiling the changed Java file in real time during running to obtain a corresponding byte code file when the Java file is found to be changed;
and the updating unit is used for loading all hot updating byte code files through the custom class loader, instantiating all objects and completing the replacement of the objects.
8. A computing device comprising a memory, a processor, and computer instructions stored on the memory and executable on the processor, wherein the processor, when executing the instructions, implements the steps of the method of any of claims 1-6.
9. A computer readable storage medium storing computer instructions which, when executed by a processor, implement the steps of the method of any one of claims 1 to 6.
CN202211116398.6A 2022-09-14 2022-09-14 Java-based hot updating method and device Pending CN116009906A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211116398.6A CN116009906A (en) 2022-09-14 2022-09-14 Java-based hot updating method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211116398.6A CN116009906A (en) 2022-09-14 2022-09-14 Java-based hot updating method and device

Publications (1)

Publication Number Publication Date
CN116009906A true CN116009906A (en) 2023-04-25

Family

ID=86027283

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211116398.6A Pending CN116009906A (en) 2022-09-14 2022-09-14 Java-based hot updating method and device

Country Status (1)

Country Link
CN (1) CN116009906A (en)

Similar Documents

Publication Publication Date Title
CN113312037B (en) Data processing method, device, equipment and storage medium applied to micro-service
US9378458B2 (en) Method and apparatus for operating a finite state machine
CN106648755B (en) Method and device for dynamically loading dex in android art environment
CN113688186B (en) Intelligent contract execution method, engine and block link point
CN113805882A (en) Method and device for developing application program, electronic equipment and storage medium
CN109740765A (en) A kind of machine learning system building method based on Amazon server
CN104699503A (en) Method and device for replacing function execution logic in Android system
CN111324343A (en) Code generation method and device
CN114115964B (en) Hot updating method and device for Unity, computing equipment and computer-readable storage medium
US9411618B2 (en) Metadata-based class loading using a content repository
CN112685020A (en) Method and device for dynamically creating service interface, electronic equipment and storage medium
CN109558121B (en) Interface driver development method, device, equipment and storage medium
CN110018831B (en) Program processing method, program processing apparatus, and computer-readable storage medium
CN111683005B (en) Internet of things intelligent gateway equipment and construction method thereof
CN114443052A (en) Dynamic specialization method and device during IL instruction operation
CN116009906A (en) Java-based hot updating method and device
CN115794162A (en) Method and device for optimizing differential update during hot update
CN115639986A (en) Software package construction method and device
US20100031256A1 (en) Method for establishing virtual operating system
WO2022078057A1 (en) Method and apparatus for publishing application package, method and apparatus for applying application package, and medium, server and device
CN115729590A (en) Service deployment method, device, equipment and computer readable storage medium
CN114995871A (en) Software version adaptation method and device, electronic equipment and storage medium
CN113296975A (en) Service calling method and device
CN113867776A (en) Method and device for publishing middle station application, electronic equipment and storage medium
CN114594981B (en) Method and device for solving generic compatibility problem during hot update

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination