CN110716720A - Method and device for realizing application hot deployment - Google Patents

Method and device for realizing application hot deployment Download PDF

Info

Publication number
CN110716720A
CN110716720A CN201810764468.6A CN201810764468A CN110716720A CN 110716720 A CN110716720 A CN 110716720A CN 201810764468 A CN201810764468 A CN 201810764468A CN 110716720 A CN110716720 A CN 110716720A
Authority
CN
China
Prior art keywords
class
file
application
original
updated
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
CN201810764468.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 Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information 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 Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201810764468.6A priority Critical patent/CN110716720A/en
Publication of CN110716720A publication Critical patent/CN110716720A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Stored Programmes (AREA)

Abstract

The invention discloses a method and a device for realizing application heat deployment, and relates to the technical field of computers. One embodiment of the method comprises: loading class files of the applications by utilizing custom class loaders corresponding to the applications one by one; when the configuration in the application is monitored to be updated in real time, a new custom class loader is used for loading the class file of the updated application; and the updated application is in one-to-one correspondence with the new class loader. The embodiment adopts real-time monitoring of the configuration in the application, and uses a new custom class loader to load the updated application; the technical means of one-to-one correspondence between the application and the class loader can facilitate dynamic file modification and timely take effect of the application in deployment, optimize the hot deployment architecture flow, increase reliability, reduce dependence on an IDE integrated development tool, and dynamically update classes without service interruption.

Description

Method and device for realizing application hot deployment
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for realizing application hot deployment.
Background
In the process of project development, page data is often changed or a data structure is often modified, in order to display the change effect, the application is often restarted to check the change effect, and recompiling and online are very time-consuming and inefficient. The hot deployment is to automatically detect the change of class (class) files and update the behavior of class in the runtime on the premise of not restarting the Java virtual machine, so that the time of application development and release can be saved. The loading mechanism of the current class loader (classloader) is delegated by parents. Hot replacement of modules can be implemented using the open Service Gateway protocol osgi (open Service Gateway initiative), and also hot deployment based on the hotspot technology.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
1. the loading sequence of the loading mechanism delegated by the parents is difficult to change, and the problem that the class needing to be monitored and changed is loaded in advance by the custom classloader is solved.
2. If there is a call relationship between modules in the OSGI architecture, the application may suffer a short functional shock due to the strong coupling.
HotSwap has strong integrated dependency on IDE and is limited to work with the recipe body, it can neither add a recipe or a domain nor modify anything else except the recipe body.
HotSwap works on the virtual machine level and relies on the internal functioning of the virtual machine JVM. Java compilers often create synthetic methods or domains, although you only modify a body of methods (say, when adding a class literal constant class literal or anonymous class or internal class, etc.). Running in debug mode often slows down the application or introduces other problems.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for implementing application hot deployment, which can facilitate dynamic modification of a file by an application in deployment, take effect in time, optimize a hot deployment architecture process, increase reliability, and reduce dependence on an IDE integrated development tool.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a method for implementing application hot deployment, including: loading class files of the applications by utilizing custom class loaders corresponding to the applications one by one; after the configuration in the application is updated, loading the class file of the updated application by using a new custom class loader; and the updated application is in one-to-one correspondence with the new class loader.
Optionally, after the configuration in the application is updated, loading the updated application by using a new custom class loader, including: monitoring compiled class files in an application, wherein when the compiled class files are updated, the compiled class files are class files of original classes; reading a class file of an original class, and modifying the type of the original class into an interface by using a first enhancement component; generating a first derived class, copying all method logics in the class file of the original class, and enabling the first derived class to realize the interface so as to finish changing the original class into the interface; setting a second derived class, the second derived class capable of implementing the interface; reading the class file of the original class to a second derived class, changing the class name of the original class by using a second enhancement component, and changing the parent class of the original class by using a third enhancement component; instantiating a behavior of the second derived class.
Optionally, the behavior of the second derived class includes: after the class is obtained through the user-defined class loader, an object is dynamically created; or modifying class.forName () and class Loadler.findClass (), and implementing the behavior of instantiating the second derivative class by utilizing the modified class.forName () and class Loadler.findClass ().
Optionally, the reading the class file of the original class includes: reading a class file of an original class from a working area; and the configuration file in the working area comprises the path of the class file of the original class.
Optionally, the method further comprises: before the application is loaded, setting a Premain method in the class file of the application; setting a manifest file, wherein the manifest file sets the attribute of Premain-Class into a Class full name of a Class; the method for the class to own the Premain; generating a jar package containing the manifest file; adding a java parameter and a jar package in the parameters of the application, executing the method of the pre main, and pre-resolving the class required when executing the method of the pre main.
Optionally, the method further comprises: reading the class file; and modifying the class file according to the updated configuration, and modifying the class name of the class file to generate a first derived class.
Optionally, the method further comprises: and replacing the original class file with the modified class file by using an interface of a ClassFileTransformer so as to prevent the original class file from being loaded.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided an apparatus for implementing application hot deployment, including: the system comprises a loading module, an updating module and a corresponding module; the loading module is used for: loading the class file of the application by using a custom class loader which is uniquely corresponding to the application; the update module is configured to: after the configuration in the application is updated, loading the class file of the updated application by using a new custom class loader; and the corresponding module is used for corresponding the updated application to the new class loader one by one.
Optionally, the update module is configured to: monitoring compiled class files in an application, wherein when the compiled class files are updated, the compiled class files are class files of original classes; reading a class file of an original class, and modifying the type of the original class into an interface by using a first enhancement component; generating a first derived class, copying all method logics in the class file of the original class, and enabling the first derived class to realize the interface so as to finish changing the original class into the interface; setting a second derived class, the second derived class capable of implementing the interface; reading the class file of the original class to a second derived class, changing the class name of the original class by using a second enhancement component, and changing the parent class of the original class by using a third enhancement component; instantiating a behavior of the second derived class.
Optionally, the update module is further configured to: after the class is obtained through the user-defined class loader, an object is dynamically created; or modifying class.forName () and class Loadler.findClass (), and implementing the behavior of instantiating the second derivative class by utilizing the modified class.forName () and class Loadler.findClass ().
Optionally, the update module is further configured to: reading a class file of an original class from a working area; and the configuration file in the working area comprises the path of the class file of the original class.
Optionally, the loading module is further configured to: before the application is loaded, setting a Premain method in the class file of the application; setting a manifest file, wherein the manifest file sets the attribute of Premain-Class into a Class full name of a Class; the method for the class to own the Premain; generating a jar package containing the manifest file; adding a java parameter and a jar package in the parameters of the application, executing the method of the pre main, and pre-resolving the class required when executing the method of the pre main.
Optionally, the update module is further configured to: reading the class file; and modifying the class file according to the updated configuration, and modifying the class name of the class file to generate a first derived class.
Optionally, the update module is further configured to: and replacing the original class file with the modified class file by using an interface of a ClassFileTransformer so as to prevent the original class file from being loaded.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided an electronic apparatus including: one or more processors; the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the method for implementing application hot deployment provided by the embodiment of the invention.
To achieve the above object, according to an aspect of the embodiments of the present invention, there is provided a computer readable medium on which a computer program is stored, the program, when executed by a processor, implementing a method for implementing application hot deployment as provided by the embodiments of the present invention.
One embodiment of the above invention has the following advantages or benefits: monitoring the configuration in the application in real time, and loading the updated application by using a new custom class loader; the technical means of one-to-one correspondence between the application and the class loader can facilitate dynamic file modification and timely take effect of the application in deployment, optimize the hot deployment architecture flow, increase reliability, reduce dependence on an IDE integrated development tool, and dynamically update classes without service interruption.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a diagram of a parent delegation loading mechanism in the prior art;
FIG. 2 is a schematic flow diagram of a prior art HotSwap thermal deployment method;
FIG. 3 is a schematic diagram of a main flow of a method of implementing application hot-deployment according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of the main modules of an apparatus implementing application hot deployment according to an embodiment of the present invention;
FIG. 5 is a thermally deployed architectural diagram according to an embodiment of the present invention;
FIG. 6 is a diagram of abstraction layers, according to an embodiment of the present invention;
FIG. 7 is a flow diagram of a trigger in a core service when a configuration changes according to an embodiment of the present invention;
FIG. 8 is an enhancement component workflow diagram according to an embodiment of the invention;
FIG. 9 is an enhancement component workflow diagram according to an embodiment of the invention;
FIG. 10 is a schematic diagram of an archived file according to an embodiment of the present invention;
FIG. 11 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 12 is a schematic structural diagram of a computer system suitable for implementing a terminal device or a server according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
The technical scheme in the prior art is as follows:
FIG. 1 is a diagram of a parent delegated load mechanism in the prior art. As shown in fig. 1, the current loading mechanism is called parent delegation, and when a class loader is used to load a class, the system first asks whether the parent class of the current class loader is capable of loading, and only if the parent class cannot implement a load operation, will the task be dropped to the class loader to load. The advantage of this top-down loading approach is that each classloader performs its own loading task without repeatedly loading classes. However, this method makes the loading sequence very difficult to change, and it becomes a difficult problem to make the custom classloader load the class that needs to be monitored and changed in advance.
OSGI module, the most key idea of OSGI is application module (bundle) and each bundle has its own class loader, when the bundle needs to be updated, the hot replacement of the module can be realized by replacing the bundle and its class loader together. Although the presence of the OSGI architecture makes module restart possible, such an operation still causes a brief functional shock to the application if there is a call relationship between the modules.
Fig. 2 is a schematic flow diagram of a prior art hot deployment method for a HotSwap. As shown in FIG. 2, the HotSwap and Instrumentation techniques are incorporated into the Debugger API, which allows a Debugger to update the byte-code of a class with the same class identification. This means that all objects can reference an updated class and execute new code when their methods are invoked, which avoids the need to reload containers whenever the bytecode of a class is modified. The dependency of the HotSwap on the integration of the IDE is strong and the HotSwap is limited to acting on the recipe body, except that it can neither add a recipe or a domain nor modify anything else. Meanwhile, the HotSwap works on the virtual machine level and depends on the internal operation of the JVM. Although only one method body is modified (e.g., when adding a class literal constant, anonymous and internal class, etc.), Java compilers often create synthetic methods or domains. Running in debug mode often slows down the application or introduces other problems
FIG. 3 is a schematic diagram of a main flow of a method of implementing application hot-deployment according to an embodiment of the present invention; as shown in fig. 3, an embodiment of the present invention provides a method for implementing application hot deployment, including:
s301, loading class files of the applications by using custom class loaders corresponding to the applications one by one;
s302, after the configuration in the application is updated, loading the class file of the updated application by using a new custom class loader;
and S303, corresponding the updated application to the new class loader one by one.
Monitoring the configuration in the application in real time, and loading the updated application by using a new custom class loader; the technical means of one-to-one correspondence between the application and the class loader can facilitate dynamic file modification and timely take effect of the application in deployment, optimize the hot deployment architecture flow, increase reliability, reduce dependence on an IDE integrated development tool, and dynamically update classes without service interruption.
In the embodiment of the present invention, after the configuration in the application is updated, loading the updated application by using a new custom class loader includes: monitoring compiled class files in an application, wherein when the compiled class files are updated, the compiled class files are class files of original classes; reading a class file of an original class, and modifying the type of the original class into an interface by using a first enhancement component; generating a first derived class, copying all method logics in the class file of the original class, and enabling the first derived class to realize the interface so as to finish changing the original class into the interface; setting a second derived class, the second derived class capable of implementing the interface; reading the class file of the original class to a second derived class, changing the class name of the original class by using a second enhancement component, and changing the parent class of the original class by using a third enhancement component; instantiating a behavior of the second derived class. An adaptation (infrastructure) Java SDK is avoided except for a few places where compatibility needs to be maintained.
In this embodiment of the present invention, the behavior of the second derived class includes: after the class is obtained through the user-defined class loader, an object is dynamically created; or modifying class.forName () and class Loadler.findClass (), and implementing the behavior of instantiating the second derivative class by utilizing the modified class.forName () and class Loadler.findClass (). The results of the Reflection API (reaction of the application programming interface) can correctly include the added/deleted members in these results. forName () is a forName method using a java.lang.class package, and returns a class by a full name of the class, which is a package name plus a class name, and is loaded by JVM. So you can get this class, you can operate this class through reflection, such as get property, get method, etc. ClassLoader: the custom class loader, findClass () method represents: when the current loader loads a class, a corresponding class adjustment is found. JVM is an abbreviation of Java Virtual Machine (Java Virtual Machine), a specification for computing devices, which is an imaginary computer implemented by emulating and simulating various computer functions on a real computer.
In this embodiment of the present invention, the reading the class file of the original class includes: reading a class file of an original class from a working area; and the configuration file in the working area comprises the path of the class file of the original class. The paths include absolute paths, relative paths, and paths with placeholders. Leaving as many complete method calls as possible means that a minimizes the performance overhead and makes it lightweight.
In the embodiment of the present invention, the method further includes: before the application is loaded, setting a Premain method in the class file of the application; setting a manifest file, wherein the manifest file sets the attribute of Premain-Class into a Class full name of a Class; the method for the class to own the Premain; generating a jar package containing the manifest file; adding a java parameter and a jar package in the parameters of the application, executing the method of the pre main, and pre-resolving the class required when executing the method of the pre main. Changes to the code Annotation (Annotation) are visible to the application. Mf file: and storing label information of Jar files, wherein the label information comprises the content description of the Jar files and provides information of application programs to the JVM at runtime, most Jar files contain a default generated manifest file, and the label information can be generated by executing JAR commands or using a zip tool. The "Main-Class" attribute of this file specifies the Main Class of the program. Java is imported from JDK (JDK is a software development kit in Java language) 1.5 and beyond, and cannot be used until 1.5, and can also be called Java agent. An agent is an interceptor (interceptor) that precedes the main method, i.e., the code that executes the agent before the main method executes. Only the method of predain needs to be implemented in java5 (version) and java6 (version), and the method name of "predain" is the method name agreed by JDK.
In the embodiment of the present invention, the method further includes: reading the class file; and modifying the class file according to the updated configuration, and modifying the class name of the class file to generate a first derived class. And replacing the original class file with the modified class file by using an interface of a ClassFileTransformer so as to prevent the original class file from being loaded. ClassFileTransformer is an interface, and agents provide an implementation of this interface to convert class files, with the conversion occurring before the JVM defines the class. The above English terms are all common knowledge in the art.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided an apparatus 400 for implementing application hot deployment, including: a loading module 401, an updating module 402, and a corresponding module 403; the loading module 401 is configured to: loading class files of the applications by utilizing custom class loaders corresponding to the applications one by one; the update module 402 is configured to: after the configuration in the application is updated, loading the class file of the updated application by using a new custom class loader; a corresponding module 403, configured to correspond the updated application to the new class loader one to one. Monitoring the configuration in the application in real time, and loading the updated application by using a new custom class loader; the technical means of one-to-one correspondence between the application and the class loader can facilitate dynamic file modification and timely take effect of the application in deployment, optimize the hot deployment architecture flow, increase reliability, reduce dependence on an IDE integrated development tool, and dynamically update classes without service interruption.
In this embodiment of the present invention, the updating module 402 is configured to: monitoring compiled class files in an application, wherein when the compiled class files are updated, the compiled class files are class files of original classes; reading a class file of an original class, and modifying the type of the original class into an interface by using a first enhancement component; generating a first derived class, copying all method logics in the class file of the original class, and enabling the first derived class to realize the interface so as to finish changing the original class into the interface; setting a second derived class, the second derived class capable of implementing the interface; reading the class file of the original class to a second derived class, changing the class name of the original class by using a second enhancement component, and changing the parent class of the original class by using a third enhancement component; instantiating a behavior of the second derived class. An adaptation (infrastructure) Java SDK is avoided except for a few places where compatibility needs to be maintained.
In this embodiment of the present invention, the updating module 402 is further configured to: after the class is obtained through the user-defined class loader, an object is dynamically created; or modifying class.forName () and class Loadler.findClass (), and implementing the behavior of instantiating the second derivative class by utilizing the modified class.forName () and class Loadler.findClass (). The results of the Reflection API are adjusted so that we can correctly include the added/deleted members of these results.
In this embodiment of the present invention, the updating module 402 is further configured to: reading a class file of an original class from a working area; and the configuration file in the working area comprises the path of the class file of the original class. Leaving as many complete method calls as possible means that a minimizes the performance overhead and makes it lightweight.
In this embodiment of the present invention, the loading module 401 is further configured to: before the application is loaded, setting a Premain method in the class file of the application; setting a manifest file, wherein the manifest file sets the attribute of Premain-Class into a Class full name of a Class; the method for the class to own the Premain; generating a jar package containing the manifest file; adding a java parameter and a jar package in the parameters of the application, executing the method of the pre main, and pre-resolving the class required when executing the method of the pre main. Changes to the code Annotation (Annotation) are visible to the application.
In this embodiment of the present invention, the updating module 402 is further configured to: reading the class file; and modifying the class file according to the updated configuration, and modifying the class name of the class file to generate a first derived class. And replacing the original class file with the modified class file by using an interface of a ClassFileTransformer so as to prevent the original class file from being loaded.
The method for realizing application hot deployment of the invention is referred to as 'A' below.
FIG. 5 is an architectural diagram of a thermal deployment of an embodiment of the present invention. To support hot deployment for an application, a separate classloader may be used to load each user-defined application, as shown in FIG. 5. Then, when a user-defined application program changes, the original application program is destroyed, and then a new classloader is used to load the changed application program, while all other application programs are not disturbed at all. The core service provides services for all custom class loaders and applications.
Class files are monitored for actual compiled on disk, and classes are updated whenever a file is updated. Two significant functional features of JVM are used: abstract bytecode, and class loaders. FIG. 6 is a diagram of abstraction layers according to an embodiment of the present invention, and as shown in FIG. 6, the class loader allows A to recognize when a class is loaded and then translate the bytecode in real time to create an abstraction layer between the virtual machine and the executable code.
Fig. 7 is a flow diagram of a trigger in a core service when a configuration changes according to an embodiment of the present invention. As shown in FIG. 7, the class file is modified according to the updated configuration, and the updated class file is loaded using the new custom class loader. Monitoring compiled class files in the application, updating the compiled class files corresponding to the original files according to the updated original files, and loading the updated class files by using a new custom class loader.
FIG. 8 is a flow diagram of modifying a bytecode file (i.e., class file or class file) according to an embodiment of the invention. As shown in fig. 8, the bytecode is read in by using the ClassReader, the classvistor modifies the bytecode according to the updated configuration personalization, and the classvriter outputs the modified bytecode. And modifying the class name of the read class file, and loading the class name into a first derivative class with a brand-new name.
FIG. 9 is an enhancement component workflow diagram according to an embodiment of the invention. With reference to fig. 9:
class heavy load
1) The original class is changed into an interface
First, the class file of the original class is loaded, and a first enhancement component "ClassModifier" is defined herein, which is used for modifying the type of the original class and converting it into an interface. All method logic of the original class is removed.
2) The first derived class generated implements the interface, i.e., the original class, and after all method logic in the original class is replicated, if the class needs to be updated, a new derived class is generated and also implements the interface. The purpose of this is that, regardless of the modification, the derived classes of the same class have a common interface, and the transitions between them become opaque to the outside.
3) A second derived class is defined that enables the second derived class to implement the same original class (when the original class has been converted to an interface). Once again, the class file of the original class is loaded, where two enhancement components are defined, one being the second enhancement component "enhanced modifier", which acts to change the original class name. The third enhancement component "ExtendModifier," which functions to change the parent class of the original class.
The custom class loader also has the function of monitoring class files which are changed, and the class loader manages a timer which scans whether the class files are changed or not in turn.
4) Changing behavior of a created object
Two common methods for creating objects in the Java virtual machine are static creation, i.e. direct new one, and dynamic creation, i.e. creating objects by reflection.
Both of these creation methods cannot be established because the type of the original class has been changed in the custom loader, changing it from a class to an interface. What we do is change the act of instantiating the original class to the act of instantiating the derived class.
For the first approach, all that needs to be done is to change the static creation to get the class (class) through the class loader and then create the object dynamically. Examples are as follows:
// primitive logic
People p=new People();
// logic after change
IPeople p=(IPeople)MyClassLoader.getInstance().
Or
findClass(“com.example.People”).newInstance();
And modifying the class file by using A, finding out all statements of the objects coming out of the new, and replacing the statements with a form of obtaining the objects by using a classloader.
For the second method of creation, it is necessary to load classes through custom loaders by modifying the behavior of class.
5) Agent intercepts behavior of default loader
The A agent can provide space for the user to do some special behavior after the JVM is started and with a short gap before the application is started. A agent is easy to implement, so long as a pre main method is defined in a class. Then, a manifest file is written, and the Premain-Class attribute is set to define a Class name with the Premain method. A jar package containing the manifest file is generated. And finally, adding a java parameter to the parameters for executing the application, and adding the jar. And parameters can be added to the A agent. Thus, before the application is executed, the logic in the prestain method is preferentially executed, and class required to be loaded is preresolved.
6) Replacement of class
And replacing the original byte codes by the A agent to prevent the original byte codes from being loaded by the Java virtual machine. Only one interface of the ClassFileTransformer needs to be realized, and the class replacement function is completed by using the realization class.
FIG. 10 is a schematic diagram of an archived file according to an embodiment of the present invention. As shown in fig. 10:
archiving files
Mapping the archived applications and modules back into the workspace, the user creates an a.xml configuration file in each application and module that tells a where a can find the source file. A is integrated with the application server and is read from the workspace instead of the archive file when a certain class or resource is updated.
This allows for just-in-time updating of not only classes, but also any type of resource such as HTML, XML, JSP, CSS,. properties, etc. A Maven user does not even need to create an a.xml file because the Maven plug-in will automatically generate the file.
Configuration and metadata
Today's applications are not just classes and resources, but they are also bound together through a large amount of configuration and metadata. When a configuration change occurs, the change should be reflected to that running application. However, it is not sufficient to only make modifications to the configuration file visible, and a specific framework must reload the configuration to reflect the changes to the application.
To support these types of changes in A, an open source API may be developed that allows our team and third party donors to use the functional properties of A using the framework-specific plug-ins to propagate changes made in the configuration into the framework. For example, adding beans and dependencies in Spring in real time is supported dynamically, and various changes made in other frameworks are supported.
An embodiment of the present invention provides an electronic device, including: one or more processors; the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the method for implementing application hot deployment provided by the embodiment of the invention.
Embodiments of the present invention provide a computer readable medium, on which a computer program is stored, where the computer program, when executed by a processor, implements a method for implementing application hot deployment as provided by embodiments of the present invention.
Fig. 11 illustrates an exemplary system architecture 1100 implementing an application thermal deployment method or implementing an application thermal deployment apparatus to which embodiments of the invention may be applied.
As shown in fig. 11, the system architecture 1100 may include terminal devices 1101, 1102, 1103, a network 1104, and a server 1105. The network 1104 is a medium to provide communication links between the terminal devices 1101, 1102, 1103 and the server 1105. Network 1104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 1101, 1102, 1103 to interact with a server 1105 over a network 1104 to receive or send messages or the like. Various messaging client applications, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, etc. (examples only) may be installed on the terminal devices 1101, 1102, 1103.
The terminal devices 1101, 1102, 1103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 1105 may be a server that provides various services, such as a backend management server (for example only) that provides support for shopping-like websites browsed by users using the terminal devices 1101, 1102, 1103. The backend management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (for example, target push information, product information — just an example) to the terminal device.
It should be noted that the method for implementing deployment of application heat provided by the embodiment of the present invention is generally executed by the server 1105, and accordingly, the apparatus for implementing deployment of application heat is generally disposed in the server 1105.
It should be understood that the number of terminal devices, networks, and servers in fig. 11 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 12, shown is a block diagram of a computer system 1200 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 12 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiment of the present invention.
As shown in fig. 12, the computer system 1200 includes a Central Processing Unit (CPU)1201, which can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)1202 or a program loaded from a storage section 1208 into a Random Access Memory (RAM) 1203. In the RAM 1203, various programs and data necessary for the operation of the system 1200 are also stored. The CPU 1201, ROM 1202, and RAM 1203 are connected to each other by a bus 1204. An input/output (I/O) interface 1205 is also connected to bus 1204.
The following components are connected to the I/O interface 1205: an input section 1206 including a keyboard, a mouse, and the like; an output portion 1207 including a display device such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 1208 including a hard disk and the like; and a communication section 1209 including a network interface card such as a LAN card, a modem, or the like. The communication section 1209 performs communication processing via a network such as the internet. A driver 1210 is also connected to the I/O interface 1205 as needed. A removable medium 1211, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like, is mounted on the drive 1210 as necessary, so that a computer program read out therefrom is mounted into the storage section 1208 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 1209, and/or installed from the removable medium 1211. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 1201.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor comprises a loading module and an updating module. Where the names of these modules do not in some cases constitute a limitation on the module itself, for example, a load module may also be described as a "module that loads an application with a custom class loader that uniquely corresponds to the application.
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: s301, loading class files of the applications by using custom class loaders corresponding to the applications one by one; s302, after the configuration in the application is updated, loading the class file of the updated application by using a new custom class loader; and the updated application is in one-to-one correspondence with the new class loader.
According to the technical scheme of the embodiment of the invention, the configuration in the application is monitored in real time, and the updated application is loaded by using a new custom class loader; the technical means of one-to-one correspondence between the application and the class loader can facilitate dynamic file modification and timely take effect of the application in deployment, optimize the hot deployment architecture flow, increase reliability, reduce dependence on an IDE integrated development tool, and dynamically update classes without service interruption.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (16)

1. A method for implementing application hot deployment, comprising:
loading class files of the applications by utilizing custom class loaders corresponding to the applications one by one;
when the configuration in the application is monitored to be updated in real time, a new custom class loader is used for loading the class file of the updated application;
and the updated application is in one-to-one correspondence with the new class loader.
2. The method of claim 1, wherein loading the updated application with a new custom class loader after the configuration in the application is updated comprises:
monitoring compiled class files in an application, wherein when the compiled class files are updated, the compiled class files are class files of original classes;
reading a class file of an original class, and modifying the type of the original class into an interface by using a first enhancement component; generating a first derived class, copying all method logics in the class file of the original class, and enabling the first derived class to realize the interface so as to finish changing the original class into the interface;
setting a second derived class, the second derived class capable of implementing the interface;
reading the class file of the original class to a second derived class, changing the class name of the original class by using a second enhancement component, and changing the parent class of the original class by using a third enhancement component;
instantiating a behavior of the second derived class.
3. The method of claim 2, wherein the act of instantiating the second derived class comprises:
after the class is obtained through the user-defined class loader, an object is dynamically created;
or modifying class.forName () and class Loadler.findClass (), and implementing the behavior of instantiating the second derivative class by utilizing the modified class.forName () and class Loadler.findClass ().
4. The method of claim 2, wherein reading the class file of the original class comprises:
reading a class file of an original class from a working area;
and the configuration file in the working area comprises the path of the class file of the original class.
5. The method of claim 1, further comprising:
before the application is loaded, setting a Premain method in the class file of the application;
setting a manifest file, wherein the manifest file sets the attribute of Premain-Class into a Class full name of a Class; the method for the class to own the Premain;
generating a jar package containing the manifest file;
adding a java parameter and a jar package in the parameters of the application, executing the method of the pre main, and pre-resolving the class required when executing the method of the pre main.
6. The method of claim 2, further comprising:
reading the class file;
and modifying the class file according to the updated configuration, and modifying the class name of the class file to generate a first derived class.
7. The method of claim 6, further comprising:
and replacing the original class file with the modified class file by using an interface of a ClassFileTransformer so as to prevent the original class file from being loaded.
8. An apparatus for enabling application hot deployment, comprising: the system comprises a loading module, an updating module and a corresponding module;
the loading module is used for: loading the class file of the application by using a custom class loader which is uniquely corresponding to the application;
the update module is configured to: after the configuration in the application is updated, loading the class file of the updated application by using a new custom class loader;
the corresponding module is configured to: and the updated application corresponds to the new class loader one to one.
9. The apparatus of claim 1, wherein the update module is configured to:
monitoring compiled class files in an application, wherein when the compiled class files are updated, the compiled class files are class files of original classes;
reading a class file of an original class, and modifying the type of the original class into an interface by using a first enhancement component; generating a first derived class, copying all method logics in the class file of the original class, and enabling the first derived class to realize the interface so as to finish changing the original class into the interface;
setting a second derived class, the second derived class capable of implementing the interface;
reading the class file of the original class to a second derived class, changing the class name of the original class by using a second enhancement component, and changing the parent class of the original class by using a third enhancement component;
instantiating a behavior of the second derived class.
10. The apparatus of claim 2, wherein the update module is further configured to:
after the class is obtained through the user-defined class loader, an object is dynamically created;
or modifying class.forname () and class loader.findclass (), and instantiating the behavior of the second derived class by utilizing the modified class.forname () and class loader.findclass ().
11. The apparatus of claim 2, wherein the update module is further configured to:
reading a class file of an original class from a working area;
and the configuration file in the working area comprises the path of the class file of the original class.
12. The apparatus of claim 1, wherein the loading module is further configured to:
before the application is loaded, setting a Premain method in the class file of the application;
setting a manifest file, wherein the manifest file sets the attribute of Premain-Class into a Class full name of a Class; the method for the class to own the Premain;
generating a jar package containing the manifest file;
adding a java parameter and a jar package in the parameters of the application, executing the method of the pre main, and pre-resolving the class required when executing the method of the pre main.
13. The apparatus of claim 9, wherein the update module is further configured to:
reading the class file;
and modifying the class file according to the updated configuration, and modifying the class name of the class file to generate a first derived class.
14. The apparatus of claim 13, wherein the update module is further configured to:
and replacing the original class file with the modified class file by using an interface of a ClassFileTransformer so as to prevent the original class file from being loaded.
15. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.
16. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-7.
CN201810764468.6A 2018-07-12 2018-07-12 Method and device for realizing application hot deployment Pending CN110716720A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810764468.6A CN110716720A (en) 2018-07-12 2018-07-12 Method and device for realizing application hot deployment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810764468.6A CN110716720A (en) 2018-07-12 2018-07-12 Method and device for realizing application hot deployment

Publications (1)

Publication Number Publication Date
CN110716720A true CN110716720A (en) 2020-01-21

Family

ID=69208389

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810764468.6A Pending CN110716720A (en) 2018-07-12 2018-07-12 Method and device for realizing application hot deployment

Country Status (1)

Country Link
CN (1) CN110716720A (en)

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111324359A (en) * 2020-02-27 2020-06-23 支付宝(杭州)信息技术有限公司 Plug-in deployment method and device
CN111538545A (en) * 2020-04-23 2020-08-14 京东方科技集团股份有限公司 Java application running method, device, medium and electronic equipment
CN112463194A (en) * 2020-11-30 2021-03-09 深圳市优必选科技股份有限公司 File data compatibility method and device, terminal equipment and storage medium
CN112764827A (en) * 2020-12-31 2021-05-07 重庆广播电视大学重庆工商职业学院 Java class hot loading method with safety verification
CN112835865A (en) * 2021-03-31 2021-05-25 中国工商银行股份有限公司 Application hot deployment system, method and device
CN113253990A (en) * 2020-02-13 2021-08-13 北京沃东天骏信息技术有限公司 Method, device, equipment and computer readable medium for updating software
WO2021179842A1 (en) * 2020-03-13 2021-09-16 华为技术有限公司 Integrated development environment construction method, apparatus, and device, and medium
CN118192984A (en) * 2024-03-21 2024-06-14 山东中创软件商用中间件股份有限公司 Class loading method, device, equipment and storage medium of page compiling stage

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113253990A (en) * 2020-02-13 2021-08-13 北京沃东天骏信息技术有限公司 Method, device, equipment and computer readable medium for updating software
CN111324359A (en) * 2020-02-27 2020-06-23 支付宝(杭州)信息技术有限公司 Plug-in deployment method and device
WO2021179842A1 (en) * 2020-03-13 2021-09-16 华为技术有限公司 Integrated development environment construction method, apparatus, and device, and medium
CN111538545A (en) * 2020-04-23 2020-08-14 京东方科技集团股份有限公司 Java application running method, device, medium and electronic equipment
CN111538545B (en) * 2020-04-23 2024-07-12 京东方科技集团股份有限公司 Java application running method, java application running device, java application running medium and electronic equipment
CN112463194A (en) * 2020-11-30 2021-03-09 深圳市优必选科技股份有限公司 File data compatibility method and device, terminal equipment and storage medium
CN112463194B (en) * 2020-11-30 2023-12-15 深圳市优必选科技股份有限公司 File data compatible method and device, terminal equipment and storage medium
CN112764827A (en) * 2020-12-31 2021-05-07 重庆广播电视大学重庆工商职业学院 Java class hot loading method with safety verification
CN112764827B (en) * 2020-12-31 2023-04-07 重庆广播电视大学重庆工商职业学院 Java class hot loading method with safety verification
CN112835865A (en) * 2021-03-31 2021-05-25 中国工商银行股份有限公司 Application hot deployment system, method and device
CN118192984A (en) * 2024-03-21 2024-06-14 山东中创软件商用中间件股份有限公司 Class loading method, device, equipment and storage medium of page compiling stage

Similar Documents

Publication Publication Date Title
CN110716720A (en) Method and device for realizing application hot deployment
US11178207B2 (en) Software version control without affecting a deployed container
CN106843869B (en) Front-end development engineering system and method
US8904368B2 (en) Instantiating a composite application for different target platforms
WO2016155388A1 (en) Method and device for installing and running application
US8615750B1 (en) Optimizing application compiling
US9529648B2 (en) Generic declaration of bindings between events and event handlers regardless of runtime structure
US8812683B2 (en) Service scripting framework
US9569292B2 (en) Remotable contracts for the web
WO2020063252A1 (en) Method and device for isolating multiple version dependency
US9047407B2 (en) State capture after execution in dependent sequences
JP2009512063A (en) Discover, qualify, and launch software add-in components
CN110389786B (en) Kernel management method, electronic device and computer-readable storage medium
US9459859B2 (en) Template derivation for configuration object management
US20190034178A1 (en) Compiling non-native constants
US12061901B2 (en) Documentation enforcement during compilation
CN108845864B (en) Spring frame-based JVM garbage recycling method and device
US20130125093A1 (en) Generating object-oriented programming language code from a multi-domain dynamic simulation model
CN116685946A (en) Reloading of updated shared libraries without stopping execution of an application
WO2023083071A1 (en) View interaction method and apparatus, electronic device, and computer readable medium
JP2006276939A (en) Program starting method for virtual machine, and client server system
US20170222944A1 (en) Computing resource deployment in non-mutually configurable environments
CN113778388A (en) Program development method and device
CN109271182B (en) Method and device for upgrading search engine
Zhou et al. MCAF: Developing an Annotation‐Based Offloading Framework for Mobile Cloud Computing

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