CN110716720A - Method and device for realizing application hot deployment - Google Patents
Method and device for realizing application hot deployment Download PDFInfo
- 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
- derived
- 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
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/60—Software deployment
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/31—Programming languages or programming paradigms
- G06F8/315—Object-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
本发明公开了一种实现应用热部署方法和装置,涉及计算机技术领域。该方法的一具体实施方式包括:利用与应用一一对应的自定义类加载器加载所述应用的类文件;当实时监控到所述应用中的配置更新后,使用新的自定义类加载器加载更新后的应用的类文件;将所述更新后的应用与所述新的类加载器一一对应。该实施方式采用实时监控到所述应用中的配置,使用新的自定义类加载器加载更新后的应用;应用与类加载器一一对应的技术手段,能够方便部署中的应用动态修改文件并及时生效,优化热部署架构流程,增加可靠性,减少对IDE集成开发工具的依赖,不停服务来动态更新类。
The invention discloses a method and device for realizing application hot deployment, and relates to the technical field of computers. A specific implementation of the method includes: using a custom class loader corresponding to the application to load the class file of the application; when the configuration update in the application is monitored in real time, using a new custom class loader Load the class file of the updated application; and make a one-to-one correspondence between the updated application and the new class loader. This 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 the application in deployment to dynamically modify the file and It takes effect in a timely manner, optimizes the hot deployment architecture process, increases reliability, reduces the dependence on IDE integrated development tools, and dynamically updates classes through non-stop services.
Description
技术领域technical field
本发明涉及计算机技术领域,尤其涉及一种实现应用热部署的方法和装置。The present invention relates to the field of computer technologies, and in particular, to a method and apparatus for implementing application hot deployment.
背景技术Background technique
在项目开发过程中,常常会改动页面数据或者修改数据结构,为了显示改动效果,往往需要重启应用查看改变效果,重新编译上线非常费时低效。热部署是在不重启Java虚拟机的前提下,自动侦测到类(class)文件的变化,更新运行时class的行为,可以节省应用开发和发布的时间。目前类加载器(classloader)的加载机制为双亲委派。可以利用开放服务网关协议OSGI(Open Service Gateway Initiative)实现模块的热替换,还有基于HotSwap技术的热部署。In the process of project development, page data or data structure are often changed. In order to display the effect of the change, it is often necessary to restart the application to check the effect of the change. Recompilation is time-consuming and inefficient. Hot deployment is to automatically detect changes in class files and update the behavior of classes at runtime without restarting the Java virtual machine, which can save time for application development and release. The current loading mechanism of classloaders is parental delegation. You can use the Open Service Gateway Initiative (OSGI) to realize hot replacement of modules, as well as hot deployment based on HotSwap technology.
在实现本发明过程中,发明人发现现有技术中至少存在如下问题:In the process of realizing the present invention, the inventor found that there are at least the following problems in the prior art:
1.双亲委派的加载机制的加载顺序很难改变,让自定义classloader抢先加载需要监听改变的类成为了一个难题。1. The loading order of the parent-delegated loading mechanism is difficult to change, making it difficult for custom classloaders to preemptively load classes that need to be monitored for changes.
2.在OSGI架构中如果模块之间有调用关系的话,由于耦合性强然会让应用出现短暂的功能性休克。2. In the OSGI architecture, if there is a calling relationship between modules, the application will have a short-term functional shock due to the coupling.
3.HotSwap对IDE的集成依赖性强,且仅限于对方法体起作用,除了方法体之外,它既不能添加方法或域,也不能修改其他任何东西。3. HotSwap has a strong integration dependency on IDE, and is limited to working on method bodies. It can neither add methods or fields, nor modify anything other than method bodies.
4.HotSwap是工作在虚拟机层面上,且依赖于虚拟机JVM的内部运作。Java编译器常常会创建合成的方法或是域,尽管你仅是修改了一个方法体(比如说,在添加一个类字面常量class literal或匿名的类或内部的类的时候等等)。在调试模式下运行常常会降低应用的速度或是引入其他的问题。4.HotSwap works at the virtual machine level and depends on the inner workings of the virtual machine JVM. Java compilers often create synthetic methods or fields, even if you only modify a method body (for example, when adding a class literal or an anonymous class or an inner class, etc.). Running in debug mode often slows down the application or introduces other problems.
发明内容SUMMARY OF THE INVENTION
有鉴于此,本发明实施例提供一种实现应用热部署的方法和装置,能够方便部署中的应用动态修改文件并及时生效、优化热部署架构流程,增加可靠性,减少对IDE集成开发工具的依赖。In view of this, the embodiments of the present invention provide a method and apparatus for implementing hot deployment of applications, which can facilitate the application in deployment to dynamically modify files and take effect in time, optimize the architecture process of hot deployment, increase reliability, and reduce the complexity of IDE integrated development tools. rely.
为实现上述目的,根据本发明实施例的一个方面,提供了一种实现应用热部署的方法,包括:利用与应用一一对应的自定义类加载器加载所述应用的类文件;当所述应用中的配置更新后,使用新的自定义类加载器加载更新后的应用的类文件;将所述更新后的应用与所述新的类加载器一一对应。In order to achieve the above object, according to an aspect of the embodiments of the present invention, a method for implementing hot deployment of an application is provided, including: loading a class file of the application by using a custom class loader corresponding to the application one-to-one; After the configuration in the application is updated, a new custom class loader is used to load the class file of the updated application; and the updated application is in a one-to-one correspondence with the new class loader.
可选地,当所述应用中的配置更新后,使用新的自定义类加载器加载更新后的应用,包括:监控应用中已编译的类文件,当所述已编译的类文件更新,所述已编译的类文件为原始类的类文件;读取原始类的类文件,使用第一增强组件将原始类的类型修改为接口;生成第一派生类,复制原始类的类文件中的所有方法逻辑,使第一派生类实现所述接口,以完成将原始类变为接口;设置第二派生类,所述第二派生类能够实现所述接口;读取原始类的类文件至第二派生类,利用第二增强组件改变原始类的类名,利用第三增强组件改变原始类的父类;实例化第二派生类的行为。Optionally, when the configuration in the application is updated, use a new custom class loader to load the updated application, including: monitoring the compiled class file in the application, when the compiled class file is updated, all Describe the compiled class file as the class file of the original class; read the class file of the original class, use the first enhancement component to modify the type of the original class to an interface; generate the first derived class, copy all the class files of the original class Method logic, make the first derived class implement the interface to complete the transformation of the original class into an interface; set a second derived class, the second derived class can implement the interface; read the class file of the original class to the second derived class For derived classes, use the second enhanced component to change the class name of the original class, and use the third enhanced component to change the parent class of the original class; instantiate the behavior of the second derived class.
可选地,所述第二派生类的行为,包括:通过自定义类加载器获取类后,动态创建对象;或修改Class.forName()和ClassLoader.findClass(),利用修改后的Class.forName()和ClassLoader.findClass(),实现实例化第二派生类的行为。Optionally, the behavior of the second derived class includes: dynamically creating an object after acquiring the class through a custom class loader; or modifying Class.forName() and ClassLoader.findClass(), using the modified Class.forName () and ClassLoader.findClass(), which implements the behavior of instantiating the second derived class.
可选地,所述读取原始类的类文件,包括:从工作区中读取原始类的类文件;其中,所述工作区中的配置文件中包括原始类的类文件的路径。Optionally, the reading the class file of the original class includes: reading the class file of the original class from the workspace; wherein the configuration file in the workspace includes the path of the class file of the original class.
可选地,所述方法还包括:加载所述应用之前,在所述应用的类文件中设置一个premain的方法;设置manifest文件,所述manifest文件将Premain-Class属性设置成一个类的类全名;该类拥有所述premain的方法;生成包含所述manifest文件的jar包;在所述应用的参数中增加-javaagent参数和jar包,执行premain的方法,并预解析在执行premain的方法时所需要的类。Optionally, the method further includes: before loading the application, a method of setting a premain in the class file of the application; setting a manifest file, where the manifest file sets the Premain-Class attribute to the class full of a class Name; this class has the method of the premain; generate a jar package containing the manifest file; add the -javaagent parameter and the jar package to the parameters of the application, execute the method of premain, and pre-parse when executing the method of premain required class.
可选地,所述方法还包括:读取类文件;根据更新后的配置修改所述类文件,并修改所述类文件的类名,以生成第一派生类。Optionally, the method further includes: reading a class file; modifying the class file according to the updated configuration, and modifying the class name of the class file to generate the first derived class.
可选地,所述方法还包括:利用ClassFileTransformer的接口将原始类文件替换为修改后的类文件,以阻止原始类文件被加载。Optionally, the method further includes: using the interface of ClassFileTransformer to replace the original class file with the modified class file to prevent the original class file from being loaded.
为实现上述目的,根据本发明实施例的一个方面,提供了一种实现应用热部署的装置,包括:加载模块、更新模块、对应模块;所述加载模块,用于:利用与应用唯一对应的自定义类加载器加载所述应用的类文件;所述更新模块,用于:当所述应用中的配置更新后,使用新的自定义类加载器加载更新后的应用的类文件;所述对应模块,用于将所述更新后的应用与所述新的类加载器一一对应。In order to achieve the above object, according to an aspect of the embodiments of the present invention, there is provided a device for implementing hot deployment of applications, including: a loading module, an updating module, and a corresponding module; the loading module is used for: using a unique corresponding to the application. The custom class loader loads the class file of the application; the update module is used for: after the configuration in the application is updated, use the new custom class loader to load the class file of the updated application; the The corresponding module is used for one-to-one correspondence between the updated application and the new class loader.
可选地,所述更新模块,用于:监控应用中已编译的类文件,当所述已编译的类文件更新,所述已编译的类文件为原始类的类文件;读取原始类的类文件,使用第一增强组件将原始类的类型修改为接口;生成第一派生类,复制原始类的类文件中的所有方法逻辑,使第一派生类实现所述接口,以完成将原始类变为接口;设置第二派生类,所述第二派生类能够实现所述接口;读取原始类的类文件至第二派生类,利用第二增强组件改变原始类的类名,利用第三增强组件改变原始类的父类;实例化第二派生类的行为。Optionally, the update module is used for: monitoring the compiled class file in the application, when the compiled class file is updated, the compiled class file is the class file of the original class; class file, use the first enhanced component to modify the type of the original class into an interface; generate the first derived class, copy all the method logic in the class file of the original class, and make the first derived class implement the interface, so as to complete the transformation of the original class become an interface; set a second derived class that can implement the interface; read the class file of the original class to the second derived class, use the second enhanced component to change the class name of the original class, and use the third Enhanced component changes the parent class of the original class; instantiates the behavior of the second derived class.
可选地,所述更新模块,还用于:通过自定义类加载器获取类后,动态创建对象;或修改Class.forName()和ClassLoader.findClass(),利用修改后的Class.forName()和ClassLoader.findClass(),实现实例化第二派生类的行为。Optionally, the update module is also used to: dynamically create an object after acquiring a class through a custom class loader; or modify Class.forName() and ClassLoader.findClass(), and use the modified Class.forName() and ClassLoader.findClass(), which implements the behavior of instantiating the second derived class.
可选地,所述更新模块,还用于:从工作区中读取原始类的类文件;其中,所述工作区中的配置文件中包括原始类的类文件的路径。Optionally, the update module is further configured to: read the class file of the original class from the workspace; wherein the configuration file in the workspace includes the path of the class file of the original class.
可选地,所述加载模块,还用于:加载所述应用之前,在所述应用的类文件中设置一个premain的方法;设置manifest文件,所述manifest文件将Premain-Class属性设置成一个类的类全名;该类拥有所述premain的方法;生成包含所述manifest文件的jar包;在所述应用的参数中增加-javaagent参数和jar包,执行premain的方法,并预解析在执行premain的方法时所需要的类。Optionally, the loading module is further used for: setting a premain method in the class file of the application before loading the application; setting a manifest file, where the manifest file sets the Premain-Class attribute to a class The full name of the class; this class has the method of the premain; generate a jar package containing the manifest file; add the -javaagent parameter and the jar package to the parameters of the application, execute the method of premain, and pre-parse before executing the premain The class required for the method.
可选地,所述更新模块,还用于:读取类文件;根据更新后的配置修改所述类文件,并修改所述类文件的类名,以生成第一派生类。Optionally, the updating module is further configured to: read the class file; modify the class file according to the updated configuration, and modify the class name of the class file to generate the first derived class.
可选地,所述更新模块,还用于:利用ClassFileTransformer的接口将原始类文件替换为修改后的类文件,以阻止原始类文件被加载。Optionally, the update module is further configured to: replace the original class file with the modified class file by using the interface of ClassFileTransformer, so as to prevent the original class file from being loaded.
为实现上述目的,根据本发明实施例的一个方面,提供了一种电子设备,包括:一个或多个处理器;存储装置,用于存储一个或多个程序,当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现如本发明实施例提供的实现应用热部署的方法。To achieve the above object, according to an aspect of the embodiments of the present invention, an electronic device is provided, including: one or more processors; a storage device for storing one or more programs, when the one or more programs Executed by the one or more processors, so that the one or more processors implement the method for implementing application hot deployment as provided by the embodiments of the present invention.
为实现上述目的,根据本发明实施例的一个方面,提供了一种计算机可读介质,其上存储有计算机程序,所述程序被处理器执行时实现如本发明实施例提供的实现应用热部署的方法。In order to achieve the above object, according to an aspect of the embodiments of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the implementation of hot deployment of applications as provided by the embodiments of the present invention is realized. Methods.
上述发明中的一个实施例具有如下优点或有益效果:采用实时监控到所述应用中的配置,使用新的自定义类加载器加载更新后的应用;应用与类加载器一一对应的技术手段,能够方便部署中的应用动态修改文件并及时生效,优化热部署架构流程,增加可靠性,减少对IDE集成开发工具的依赖,不停服务来动态更新类。An embodiment of the above invention has the following advantages or beneficial effects: adopting the configuration monitored in the application in real time, using a new custom class loader to load the updated application; applying technical means corresponding to the class loader one-to-one , which can facilitate the application in deployment to dynamically modify files and take effect in time, optimize the hot deployment architecture process, increase reliability, reduce the dependence on IDE integrated development tools, and keep services to dynamically update classes.
上述的非惯用的可选方式所具有的进一步效果将在下文中结合具体实施方式加以说明。Further effects of the above non-conventional alternatives will be described below in conjunction with specific embodiments.
附图说明Description of drawings
附图用于更好地理解本发明,不构成对本发明的不当限定。其中:The accompanying drawings are used for better understanding of the present invention and do not constitute an improper limitation of the present invention. in:
图1是现有技术中的双亲委派加载机制示意图;1 is a schematic diagram of a parent delegation loading mechanism in the prior art;
图2是现有技术的HotSwap热部署方法的流程示意图;Fig. 2 is the schematic flow chart of the HotSwap hot deployment method of the prior art;
图3是根据本发明实施例的实现应用热部署的方法的主要流程的示意图;3 is a schematic diagram of a main process of a method for implementing application hot deployment according to an embodiment of the present invention;
图4是根据本发明实施例的实现应用热部署的装置的主要模块的示意图;4 is a schematic diagram of main modules of an apparatus for implementing application hot deployment according to an embodiment of the present invention;
图5是根据本发明实施例的热部署的架构图;FIG. 5 is an architectural diagram of hot deployment according to an embodiment of the present invention;
图6是根据本发明实施例的抽象层示意图;6 is a schematic diagram of an abstraction layer according to an embodiment of the present invention;
图7是根据本发明实施例的当配置改变时核心服务中会触发的流程图;7 is a flow chart that is triggered in a core service when a configuration is changed according to an embodiment of the present invention;
图8是根据本发明实施例的增强组件工作流程图;FIG. 8 is a work flow diagram of an enhancement component according to an embodiment of the present invention;
图9是根据本发明实施例的增强组件工作流程图;FIG. 9 is a work flow diagram of an enhancement component according to an embodiment of the present invention;
图10是根据本发明实施例的归档文件示意图;10 is a schematic diagram of an archive file according to an embodiment of the present invention;
图11是本发明实施例可以应用于其中的示例性系统架构图;FIG. 11 is an exemplary system architecture diagram to which an embodiment of the present invention may be applied;
图12是适于用来实现本发明实施例的终端设备或服务器的计算机系统的结构示意图。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 ways
以下结合附图对本发明的示范性实施例做出说明,其中包括本发明实施例的各种细节以助于理解,应当将它们认为仅仅是示范性的。因此,本领域普通技术人员应当认识到,可以对这里描述的实施例做出各种改变和修改,而不会背离本发明的范围和精神。同样,为了清楚和简明,以下的描述中省略了对公知功能和结构的描述。Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, which include various details of the embodiments of the present invention to facilitate understanding and should be considered as exemplary only. 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 from the following description for clarity and conciseness.
现有技术的技术方案:Technical solutions of the prior art:
图1是现有技术中的双亲委派加载机制示意图。如图1所示,目前的加载机制称为双亲委派,系统在使用一个classloader来加载类时,会先询问当前classloader的父类是否有能力加载,如果父类无法实现加载操作才会将任务下放到该classloader来加载。这种自上而下的加载方式的好处是让每个classloader执行自己的加载任务,不会重复加载类。但是这种方式却使加载顺序非常难改变,让自定义classloader抢先加载需要监听改变的类成为了一个难题。FIG. 1 is a schematic diagram of a parent delegation loading mechanism in the prior art. As shown in Figure 1, the current loading mechanism is called parental delegation. When the system uses a classloader to load a class, it will first ask whether the parent class of the current classloader has the ability to load, and if the parent class cannot implement the loading operation, the task will be delegated. to the classloader to load. The advantage of this top-down loading method is that each classloader performs its own loading tasks and does not load classes repeatedly. However, this method makes it very difficult to change the loading order, and it becomes a difficult problem for the custom classloader to preemptively load the classes that need to be monitored for changes.
OSGI模块,OSGI的最关键理念就是应用模块(bundle)化,对于每一个bundle都有其自己的类加载器,当需要更新bundle时,把bundle和它的类加载器一起替换掉就可以实现模块的热替换。虽然OSGI架构的出现让模块重启成为可能,但是如果模块之间有调用关系的话,这样的操作依然会让应用出现短暂的功能性休克。OSGI module, the key concept of OSGI is to apply module (bundle), for each bundle has its own class loader, when the bundle needs to be updated, replace the bundle and its class loader together to realize the module hot replacement. Although the emergence of the OSGI architecture makes it possible to restart modules, if there is a calling relationship between modules, such an operation will still cause a short-term functional shock to the application.
图2是现有技术的HotSwap热部署方法的流程示意图。如图2所示,将HotSwap和Instrumentation技术合成到Debugger API内部,其允许调试者使用同一个类标识来更新类的字节码。这意味着所有对象都可以引用一个更新后的类,并在它们的方法被调用的时候执行新的代码,这就避免了无论何时只要有类的字节码被修改就要重载容器的这种要求。HotSwap对IDE的集成的依赖性强,且HotSwap仅限于对方法体起作用,除了方法体之外,它既不能添加方法或域,也不能修改其他任何东西。同时HotSwap是工作在虚拟机层面上,且依赖于JVM的内部运作。尽管仅是修改了一个方法体(比如说,在添加一个类字面常量(class literal)、匿名的和内部的类的时候等等)的时候,Java编译器常常会创建合成的方法或是域。在调试模式下运行常常会降低应用的速度或是引入其他的问题FIG. 2 is a schematic flowchart of a HotSwap hot deployment method in the prior art. As shown in Figure 2, the HotSwap and Instrumentation techniques are synthesized into the Debugger API, which allows the debugger to update the bytecode of a class with the same class ID. This means that all objects can reference an updated class and execute the new code when their methods are called, which avoids reloading the container whenever the class's bytecode is modified. this requirement. HotSwap has a strong dependence on IDE integration, and HotSwap is limited to working on method bodies. It can neither add methods or fields, nor modify anything other than method bodies. At the same time, HotSwap works at the virtual machine level and depends on the inner workings of the JVM. Java compilers often create synthetic methods or fields when only modifying a method body (eg, when adding a class literal, anonymous and inner classes, etc.). Running in debug mode often slows down the application or introduces other problems
图3是根据本发明实施例的实现应用热部署的方法的主要流程的示意图;如图3所示,本发明实施例提供了一种实现应用热部署的方法,包括:3 is a schematic diagram of a main process of a method for 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.利用与应用一一对应的自定义类加载器加载所述应用的类文件;Step S301. Use a custom class loader corresponding to the application to load the class file of the application;
步骤S302.当所述应用中的配置更新后,使用新的自定义类加载器加载更新后的应用的类文件;Step S302. When the configuration in the application is updated, use a new custom class loader to load the class file of the updated application;
步骤S303.将所述更新后的应用与所述新的类加载器一一对应。Step S303. One-to-one correspondence between the updated application and the new class loader.
采用实时监控到所述应用中的配置,使用新的自定义类加载器加载更新后的应用;应用与类加载器一一对应的技术手段,能够方便部署中的应用动态修改文件并及时生效,优化热部署架构流程,增加可靠性,减少对IDE集成开发工具的依赖,不停服务来动态更新类。The configuration in the application is monitored in real time, and a new custom class loader is used to load the updated application; the technical means of one-to-one correspondence between the application and the class loader can facilitate the application in deployment to dynamically modify the file and take effect in time, Optimize the hot deployment architecture process, increase reliability, reduce the dependence on IDE integrated development tools, and dynamically update classes with non-stop services.
本发明实施例中,当所述应用中的配置更新后,使用新的自定义类加载器加载更新后的应用,包括:监控应用中已编译的类文件,当所述已编译的类文件更新,所述已编译的类文件为原始类的类文件;读取原始类的类文件,使用第一增强组件将原始类的类型修改为接口;生成第一派生类,复制原始类的类文件中的所有方法逻辑,使第一派生类实现所述接口,以完成将原始类变为接口;设置第二派生类,所述第二派生类能够实现所述接口;读取原始类的类文件至第二派生类,利用第二增强组件改变原始类的类名,利用第三增强组件改变原始类的父类;实例化第二派生类的行为。避免了改编(instrument)Java SDK,除了少数几个需要保持兼容性的地方外。In the embodiment of the present invention, after the configuration in the application is updated, using a new custom class loader to load the updated application includes: monitoring the compiled class file in the application, and when the compiled class file is updated , the compiled class file is the class file of the original class; read the class file of the original class, and use the first enhanced component to modify the type of the original class into an interface; generate the first derived class, copy the class file of the original class All method logic of the first derived class to implement the interface to complete the transformation of the original class into an interface; set the second derived class, which can implement the interface; read the class file of the original class to For the second derived class, use the second enhanced component to change the class name of the original class, and use the third enhanced component to change the parent class of the original class; instantiate the behavior of the second derived class. Instrumentation of the Java SDK is avoided, except in a few places where compatibility is required.
本发明实施例中,所述第二派生类的行为,包括:通过自定义类加载器获取类后,动态创建对象;或修改Class.forName()和ClassLoader.findClass(),利用修改后的Class.forName()和ClassLoader.findClass(),实现实例化第二派生类的行为。Reflection API(应用程序编程接口的反应)的结果,能够把这些结果中已添加/已删除的成员正确地包含进来。Class.forName()是用到了java.lang.Class包的forName方法,它是通过类的全称来返回一个类,全称是指包名称加类名称,它是通过JVM来加载的。这样你就可以获取到这个类了,你可以通过反射来操作这个类,例如获取属性,获取方法等等。ClassLoader:自定义类加载器,findClass()方法表示的是:当前加载器加载类的时候,去找到相应的类调整。JVM是Java Virtual Machine(Java虚拟机)的缩写,JVM是一种用于计算设备的规范,它是一个虚构出来的计算机,是通过在实际的计算机上仿真模拟各种计算机功能来实现的。In the embodiment of the present invention, the behavior of the second derived class includes: dynamically creating an object after acquiring the class through a custom class loader; or modifying Class.forName() and ClassLoader.findClass(), and using the modified Class .forName() and ClassLoader.findClass(), which implement the behavior of instantiating the second derived class. The results of the Reflection API (application programming interface), which correctly include the added/removed members of these results. Class.forName() uses the forName method of the java.lang.Class package. It returns a class through the full name of the class. The full name refers to the package name plus the class name, which is loaded by the JVM. In this way, you can get this class, and you can manipulate this class through reflection, such as getting properties, getting methods, etc. ClassLoader: Custom class loader. The findClass() method means: when the current loader loads the class, find the corresponding class adjustment. JVM is the abbreviation of Java Virtual Machine (Java Virtual Machine). JVM is a specification for computing devices. It is a fictional computer that is realized by simulating various computer functions on an actual computer.
本发明实施例中,所述读取原始类的类文件,包括:从工作区中读取原始类的类文件;其中,所述工作区中的配置文件中包括原始类的类文件的路径。所述路径包括绝对路径、相对路径和带占位符“*”的路径。留有尽可能多完整的方法调用,这意味着A把性能开销降低到了最小,使其轻量级化。In this embodiment of the present invention, the reading of the class file of the original class includes: reading the class file of the original class from the workspace; wherein the configuration file in the workspace includes the path of the class file of the original class. The paths include absolute paths, relative paths, and paths with placeholder "*". Leaving as many complete method calls as possible means that A minimizes the performance overhead and makes it lightweight.
本发明实施例中,所述方法还包括:加载所述应用之前,在所述应用的类文件中设置一个premain的方法;设置manifest文件,所述manifest文件将Premain-Class属性设置成一个类的类全名;该类拥有所述premain的方法;生成包含所述manifest文件的jar包;在所述应用的参数中增加-javaagent参数和jar包,执行premain的方法,并预解析在执行premain的方法时所需要的类。代码注解(Annotation)的改变对于应用来说是可见的。.MANIFEST.MF文件:存放Jar文件的标签信息,它包含了jar文件的内容描述,并在运行时向JVM提供应用程序的信息,大多数jar文件含有一个默认生成的manifest文件,执行JAR命令或使用zip工具,都可以产生它。该文件的"Main-Class"属性指定了程序的主类。-javaagent是从JDK(JDK是Java语言的软件开发工具包)1.5及以后引入的,在1.5之前无法使用,也可以叫做java代理。代理(agent)是在主main方法前的一个拦截器(interceptor),也就是在main方法执行之前,执行agent的代码。在java5(版本)和java6(版本)中只需要实现premain这个方法,这个方法名“premain”是JDK约定的方法名。In the embodiment of the present invention, the method further includes: before loading the application, a method of setting a premain in the class file of the application; setting a manifest file, where the manifest file sets the Premain-Class attribute to a class The full name of the class; this class has the method of the premain; generates a jar package containing the manifest file; adds the -javaagent parameter and the jar package to the parameters of the application, executes the method of premain, and pre-parses the method of executing premain The class required for the method. Changes to code annotations are visible to the application. .MANIFEST.MF file: Stores the label information of the Jar file, it contains the content description of the jar file, and provides application information to the JVM at runtime. Most jar files contain a default generated manifest file, execute the JAR command or It can be generated using the zip tool. The "Main-Class" property of this file specifies the main class of the program. -javaagent is introduced from JDK (JDK is a software development kit for Java language) 1.5 and later, and cannot be used before 1.5, it can also be called java agent. The agent is an interceptor before the main main method, that is, before the main method is executed, the code of the agent is executed. In java5 (version) and java6 (version), only the premain method needs to be implemented. The method name "premain" is the method name agreed by the JDK.
本发明实施例中,所述方法还包括:读取类文件;根据更新后的配置修改所述类文件,并修改所述类文件的类名,以生成第一派生类。利用ClassFileTransformer的接口将原始类文件替换为修改后的类文件,以阻止原始类文件被加载。ClassFileTransformer是接口,代理(agent)提供此接口的实现,以便转换类文件,转换发生在JVM定义类之前。以上英文术语皆为本领域的公知常识。In the embodiment of the present invention, the method further includes: reading a class file; modifying the class file according to the updated configuration, and modifying the class name of the class file to generate a first derived class. Utilize the interface of ClassFileTransformer to replace the original class file with the modified class file to prevent the original class file from being loaded. ClassFileTransformer is the interface, the agent (agent) provides the implementation of this interface in order to transform the class file, the transformation happens before the JVM defines the class. The above English terms are all common knowledge in the field.
为实现上述目的,根据本发明实施例的一个方面,提供了一种实现应用热部署的装置400,包括:加载模块401、更新模块402、对应模块403;所述加载模块401,用于:利用与应用一一对应的自定义类加载器加载所述应用的类文件;所述更新模块402,用于:当所述应用中的配置更新后,使用新的自定义类加载器加载更新后的应用的类文件;对应模块403,用于将所述更新后的应用与所述新的类加载器一一对应。采用实时监控到所述应用中的配置,使用新的自定义类加载器加载更新后的应用;应用与类加载器一一对应的技术手段,能够方便部署中的应用动态修改文件并及时生效,优化热部署架构流程,增加可靠性,减少对IDE集成开发工具的依赖,不停服务来动态更新类。To achieve the above object, according to an aspect of the embodiments of the present invention, an apparatus 400 for implementing hot deployment of applications is provided, including: a loading module 401, an updating module 402, and a corresponding module 403; the loading module 401 is used for: utilizing The custom class loader corresponding to the application loads the class file of the application; the update module 402 is used for: when the configuration in the application is updated, use the new custom class loader to load the updated The class file of the application; the corresponding module 403 is used for one-to-one correspondence between the updated application and the new class loader. The configuration in the application is monitored in real time, and a new custom class loader is used to load the updated application; the technical means of one-to-one correspondence between the application and the class loader can facilitate the application in deployment to dynamically modify the file and take effect in time, Optimize the hot deployment architecture process, increase reliability, reduce the dependence on IDE integrated development tools, and dynamically update classes with non-stop services.
本发明实施例中,所述更新模块402,用于:监控应用中已编译的类文件,当所述已编译的类文件更新,所述已编译的类文件为原始类的类文件;读取原始类的类文件,使用第一增强组件将原始类的类型修改为接口;生成第一派生类,复制原始类的类文件中的所有方法逻辑,使第一派生类实现所述接口,以完成将原始类变为接口;设置第二派生类,所述第二派生类能够实现所述接口;读取原始类的类文件至第二派生类,利用第二增强组件改变原始类的类名,利用第三增强组件改变原始类的父类;实例化第二派生类的行为。避免了改编(instrument)Java SDK,除了少数几个需要保持兼容性的地方外。In the embodiment of the present invention, the updating module 402 is used for: monitoring the compiled class file in the application, when the compiled class file is updated, the compiled class file is the class file of the original class; read In the class file of the original class, use the first enhanced component to modify the type of the original class into an interface; generate the first derived class, copy all the method logic in the class file of the original class, and make the first derived class implement the interface to complete Change the original class into an interface; set a second derived class, the second derived class can implement the interface; read the class file of the original class to the second derived class, and use the second enhanced component to change the class name of the original class, Change the parent class of the original class with a third enhancement component; instantiate the behavior of the second derived class. Instrumentation of the Java SDK is avoided, except in a few places where compatibility is required.
本发明实施例中,所述更新模块402,还用于:通过自定义类加载器获取类后,动态创建对象;或修改Class.forName()和ClassLoader.findClass(),利用修改后的Class.forName()和ClassLoader.findClass(),实现实例化第二派生类的行为。调整Reflection API的结果,这样我们就能够把这些结果中已添加/已删除的成员正确地包含进来。In the embodiment of the present invention, the update module 402 is further used to: dynamically create an object after acquiring a class through a custom class loader; or modify Class.forName() and ClassLoader.findClass(), and use the modified Class. forName() and ClassLoader.findClass(), implement the behavior of instantiating the second derived class. Adjusted Reflection API results so that we can correctly include added/removed members in these results.
本发明实施例中,所述更新模块402,还用于:从工作区中读取原始类的类文件;其中,所述工作区中的配置文件中包括原始类的类文件的路径。留有尽可能多完整的方法调用,这意味着A把性能开销降低到了最小,使其轻量级化。In this embodiment of the present invention, the updating module 402 is further configured to: read the class file of the original class from the workspace; wherein the configuration file in the workspace includes 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.
本发明实施例中,所述加载模块401,还用于:加载所述应用之前,在所述应用的类文件中设置一个premain的方法;设置manifest文件,所述manifest文件将Premain-Class属性设置成一个类的类全名;该类拥有所述premain的方法;生成包含所述manifest文件的jar包;在所述应用的参数中增加-javaagent参数和jar包,执行premain的方法,并预解析在执行premain的方法时所需要的类。代码注解(Annotation)的改变对于应用来说是可见的。In this embodiment of the present invention, the loading module 401 is further configured to: set a premain method in the class file of the application before loading the application; set a manifest file, where the manifest file sets the Premain-Class attribute The full name of a class; the class has the premain method; a jar package containing the manifest file is generated; the -javaagent parameter and the jar package are added to the parameters of the application, the premain method is executed, and pre-parsed The class required to execute the premain method. Changes to code annotations are visible to the application.
本发明实施例中,所述更新模块402,还用于:读取类文件;根据更新后的配置修改所述类文件,并修改所述类文件的类名,以生成第一派生类。利用ClassFileTransformer的接口将原始类文件替换为修改后的类文件,以阻止原始类文件被加载。In this embodiment of the present invention, the updating module 402 is further configured to: read a class file; modify the class file according to the updated configuration, and modify the class name of the class file to generate a first derived class. Utilize the interface of ClassFileTransformer to replace the original class file with the modified class file to prevent the original class file from being loaded.
下面以“A”来指代本发明的实现应用热部署的方法。Hereinafter, "A" is used to refer to the method for implementing application hot deployment of the present invention.
图5为本发明实施例的热部署的架构图。如图5所示,要一个应用支持热部署,可以对每一个用户自定义的应用程序使用一个单独的classloader进行加载。然后,当某个用户自定义的应用程序发生变化的时候,先销毁原来的应用,然后使用一个新的classloader来加载改变之后的应用,而所有的其它的应用程序不会受到一点干扰。核心服务为所有的自定义类加载器和应用提供服务。FIG. 5 is an architectural diagram of hot deployment according to an embodiment of the present invention. As shown in Figure 5, if an application supports hot deployment, a separate classloader can be used to load each user-defined application. Then, when a user-defined application changes, first destroy the original application, and then use a new classloader to load the changed application, and all other applications will not be disturbed at all. The core service provides services for all custom class loaders and applications.
工作方式是监控磁盘上实际已编译的.class文件,无论何时只要有文件被更新就更新类。用到了JVM两个显著的功能特性:抽象的字节码和类加载器。图6是根据本发明实施例的抽象层示意图,如图6所示,类加载器允许A辨别出类被加载的时刻,然后实时地翻译字节码,用以在虚拟机和可执行代码之间创建一个抽象层。The way it works is by monitoring the actual compiled .class files on disk and updating the class whenever a file is updated. Two notable features of the JVM are used: abstract bytecode and classloaders. FIG. 6 is a schematic diagram of an abstraction layer according to an embodiment of the present invention. As shown in FIG. 6 , the class loader allows A to identify the moment when the class is loaded, and then translate the bytecode in real time, so as to be used between the virtual machine and the executable code. create an abstraction layer in between.
图7是根据本发明实施例的当配置改变时核心服务中会触发的流程图。如图7所示,根据更新后的配置修改所述类文件,使用新的自定义类加载器加载更新后的类文件。监控应用中已编译的类文件,根据更新后的原文件,更新与原文件对应的已编译的类文件,使用新的自定义类加载器加载更新后的类文件。FIG. 7 is a flowchart that is triggered in a core service when a configuration is changed, 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 a new custom class loader. Monitor the compiled class files in the application, update the compiled class files corresponding to the original files according to the updated original files, and use the new custom class loader to load the updated class files.
图8是根据本发明实施例的修改字节码文件(即类文件或.class文件)的流程图。如图8所示,利用ClassReader读入字节码,ClassVisitor根据根据更新后的配置个性化修改字节码,ClassWriter输出修改后的字节码。将读取的类文件的类名做一些修改,加载成一个全新名字的第一派生类。FIG. 8 is a flowchart of modifying a bytecode file (ie, a class file or a .class file) according to an embodiment of the present invention. As shown in Figure 8, ClassReader is used to read bytecodes, ClassVisitor modifies the bytecodes according to the updated configuration, and ClassWriter outputs the modified bytecodes. Make some modifications to the class name of the read class file and load it into a first derived class with a brand new name.
图9是根据本发明实施例的增强组件工作流程图。结合图9:FIG. 9 is a work flow diagram of an enhancement component according to an embodiment of the present invention. Combined with Figure 9:
类重载class overloading
1)先将原来的类变成接口1) First turn the original class into an interface
首先load原始类的class文件,此处定义了第一增强组件“ClassModifier”,作用是修改原始类的类型,将它转换成接口。原始类的所有方法逻辑都会被去掉。First load the class file of the original class, where the first enhancement component "ClassModifier" is defined, which is used to modify the type of the original class and convert it into an interface. All method logic of the original class will be stripped.
2)生成的第一派生类都实现这个接口,即原始类,并且复制原始类中的所有方法逻辑之后如果该类需要更新,会生成一个新的派生类,也会实现这个接口。这样做的目的是不论如何修改,同一个class的派生类都有一个共同的接口,他们之间的转换变得对外不透明。2) The first derived class generated implements this interface, that is, the original class, and after copying all the method logic in the original class, if the class needs to be updated, a new derived class will be generated, which will also implement this interface. The purpose of this is that no matter how it is modified, the derived classes of the same class have a common interface, and the conversion between them becomes opaque to the outside world.
3)定义一个第二派生类,让第二派生类能够实现同一个原始类(此时原始类已经转成接口了)。再次load原始类的class文件,此处定义了两个增强组件,一个是第二增强组件“EnhancedModifier”,这个增强组件的作用是改变原有的类名。第三增强组件“ExtendModifier”,这个增强组件的作用是改变原有类的父类。3) Define a second derived class so that the second derived class can implement the same original class (the original class has been converted into an interface at this time). Load the class file of the original class again, two enhanced components are defined here, one is the second enhanced component "EnhancedModifier", the function of this enhanced component is to change the original class name. The third enhanced component "ExtendModifier", the function of this enhanced component is to change the parent class of the original class.
自定义类加载器还有一个作用是监听会发生改变的class文件,类加载器会管理一个定时器,定时依次扫描这些class文件是否改变。Another function of the custom class loader is to monitor the class files that will change. The class loader will manage a timer and regularly scan these class files for changes.
4)改变创建对象的行为4) Change the behavior of creating objects
Java虚拟机常见的创建对象的方法有两种,一种是静态创建,即直接new一个对象,一种是动态创建,通过反射的方法创建对象。There are two common methods of creating objects in the Java virtual machine, one is static creation, that is, directly new an object, and the other is dynamic creation, which creates objects through reflection.
由于已经在自定义加载器中更改了原有类的类型,把它从类改成了接口,所以这两种创建方法都无法成立。我们要做的是将实例化原始类的行为变成实例化派生类的行为。Since the type of the original class has been changed in the custom loader, it has been changed from a class to an interface, so neither of these two creation methods will work. What we're trying to do is turn the act of instantiating the original class into the act of instantiating a derived class.
对于第一种方法,需要做的是将静态创建,变为通过类加载器获取类(class),然后动态创建该对象。例子如下:For the first method, what needs to be done is to change the static creation to obtain the class (class) through the class loader, and then dynamically create the object. Examples are as follows:
//原始逻辑//original logic
People p=new People();People p = new People();
//改变后的逻辑//changed logic
IPeople p=(IPeople)MyClassLoader.getInstance().IPeople p=(IPeople)MyClassLoader.getInstance().
或or
findClass(“com.example.People”).newInstance();findClass("com.example.People").newInstance();
用A来修改class文件,查找到所有new出来的对象的语句,替换成通过classloader的形式来获取对象的形式。Use A to modify the class file, find all the statements of new objects, and replace them with the form of obtaining objects through the form of classloader.
对于第二种创建方法,需要通过修改Class.forName()和ClassLoader.findClass()的行为,使他们通过自定义加载器加载类。For the second creation method, you need to modify the behavior of Class.forName() and ClassLoader.findClass() so that they load the class through the custom loader.
5)A agent拦截默认加载器的行为5) A agent intercepts the behavior of the default loader
A agent可以在JVM启动之后,应用启动之前的短暂间隙,提供空间给用户做一些特殊行为。A agent的实现很容易,只要在一个类里面,定义一个premain的方法。然后编写一个manifest文件,将Premain-Class属性设置成定义一个拥有premain方法的类名即可。生成一个包含这个manifest文件的jar包。最后需要在执行应用的参数中增加-javaagent参数,加入这个jar。同时可以为A agent增加参数。这样在执行应用的之前,会优先执行premain方法中的逻辑,并且预解析需要加载的class。A agent can provide space for the user to perform some special actions in a short interval before the application starts after the JVM is started. The implementation of A agent is very easy, as long as a premain method is defined in a class. Then write a manifest file and set the Premain-Class property to define a class name with a premain method. Generate a jar containing this manifest file. Finally, you need to add the -javaagent parameter to the parameters of the execution application and add this jar. At the same time, parameters can be added for A agent. In this way, before executing the application, the logic in the premain method will be executed first, and the classes to be loaded will be pre-parsed.
6)替换class6) Replace class
利用A agent替换原始字节码,阻止原始字节码被Java虚拟机加载。只需要实现一个ClassFileTransformer的接口,利用这个实现类完成class替换的功能。Use A agent to replace the original bytecode to prevent the original bytecode from being loaded by the Java virtual machine. You only need to implement an interface of ClassFileTransformer, and use this implementation class to complete the function of class replacement.
图10是根据本发明实施例的归档文件示意图。如图10所示:FIG. 10 is a schematic diagram of an archive file according to an embodiment of the present invention. As shown in Figure 10:
归档文件archive file
把归档的应用和模块映射回到工作区中,用户在每个应用和模块中创建一个a.xml配置文件,该文件告诉A在哪里可以找到源文件。A与应用服务器整合在一起,当某个类或是资源被更新时,其被从工作区中而不是从归档文件中读入。To map 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 to find the source files. A is integrated with the application server, and when a class or resource is updated, it is read from the workspace instead of the archive.
这一做法不仅允许类的即时更新,且允许诸如HTML、XML、JSP、CSS、.properties等之类的任何类型的资源的即时更新。Maven用户甚至不需要创建一个a.xml文件,因为Maven插件会自动地生成该文件。This approach allows instant updating of not only classes, but any type of resource such as HTML, XML, JSP, CSS, .properties, etc. Maven users don't even need to create an a.xml file, as the Maven plugin will generate it automatically.
配置和元数据Configuration and metadata
现如今的应用已不仅仅是类和资源,它们还通过大量的配置和元数据绑定在一起。当配置发生改变时,改变应该被反映到那个正在运行的应用上。然而,仅把对配置文件的修改变成是可见的是不够的,具体的框架必须要重载配置,把改变反映到应用中才行。Applications today are not just classes and resources, they are also bound together by a lot of configuration and metadata. When configuration changes are made, the changes should be reflected in that running application. However, it is not enough to make changes to the configuration file visible, the specific framework must reload the configuration to reflect the changes in the application.
为了在A中支持这些类型的改变,可以开发一个开源的API,该API允许我们的团队和第三方的捐献者使用框架特有的插件来使用A的功能特性,把配置中所做的改变传播到框架中。例如,支持动态实时地在Spring中添加bean和依赖,以及支持在其他框架中所做的各种各样的改变等。To support these types of changes in A, an open-source API can be developed that allows our team and third-party contributors to use A's features using framework-specific plugins, propagating changes made in the configuration to in the frame. For example, support for adding beans and dependencies in Spring dynamically and in real time, as well as supporting various changes made in other frameworks, etc.
本发明实施例提供了一种电子设备,包括:一个或多个处理器;存储装置,用于存储一个或多个程序,当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现如本发明实施例提供的实现应用热部署的方法。An embodiment of the present invention provides an electronic device, including: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors , so that the one or more processors implement the method for implementing application hot deployment as provided by the embodiments of the present invention.
本发明实施例提供了一种计算机可读介质,其上存储有计算机程序,所述程序被处理器执行时实现如本发明实施例提供的实现应用热部署的方法。Embodiments of the present invention provide a computer-readable medium on which a computer program is stored, and when the program is executed by a processor, the method for implementing hot deployment of applications provided by the embodiments of the present invention is implemented.
图11示出了可以应用本发明实施例的实现应用热部署方法或实现应用热部署装置的示例性系统架构1100。FIG. 11 shows an exemplary system architecture 1100 to which an application hot deployment method or an application hot deployment apparatus may be applied to which embodiments of the present invention may be applied.
如图11所示,系统架构1100可以包括终端设备1101、1102、1103,网络1104和服务器1105。网络1104用以在终端设备1101、1102、1103和服务器1105之间提供通信链路的介质。网络1104可以包括各种连接类型,例如有线、无线通信链路或者光纤电缆等等。As shown in FIG. 11 , the system architecture 1100 may include terminal devices 1101 , 1102 , and 1103 , a network 1104 and a server 1105 . The network 1104 is a medium used to provide a communication link between the terminal devices 1101 , 1102 , 1103 and the server 1105 . The network 1104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
用户可以使用终端设备1101、1102、1103通过网络1104与服务器1105交互,以接收或发送消息等。终端设备1101、1102、1103上可以安装有各种通讯客户端应用,例如购物类应用、网页浏览器应用、搜索类应用、即时通信工具、邮箱客户端、社交平台软件等(仅为示例)。The user can use the terminal devices 1101, 1102, 1103 to interact with the server 1105 through the network 1104 to receive or send messages and the like. Various communication client applications may be installed on the terminal devices 1101 , 1102 and 1103 , such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).
终端设备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 computers, desktop computers, and the like.
服务器1105可以是提供各种服务的服务器,例如对用户利用终端设备1101、1102、1103所浏览的购物类网站提供支持的后台管理服务器(仅为示例)。后台管理服务器可以对接收到的产品信息查询请求等数据进行分析等处理,并将处理结果(例如目标推送信息、产品信息--仅为示例)反馈给终端设备。The server 1105 may be a server that provides various services, such as a background management server that provides support for shopping websites browsed by the terminal devices 1101 , 1102 , and 1103 (just an example). The background management server can analyze and process the received product information query request and other data, and feed back the processing results (such as target push information, product information—just an example) to the terminal device.
需要说明的是,本发明实施例所提供的实现应用热部署方法一般由服务器1105执行,相应地,实现应用热部署装置一般设置于服务器1105中。It should be noted that, the method for implementing hot application deployment provided by the embodiment of the present invention is generally executed by the server 1105 , and accordingly, the apparatus for implementing hot application deployment is generally set in the server 1105 .
应该理解,图11中的终端设备、网络和服务器的数目仅仅是示意性的。根据实现需要,可以具有任意数目的终端设备、网络和服务器。It should be understood that the numbers of terminal devices, networks and servers in FIG. 11 are merely illustrative. There can be any number of terminal devices, networks and servers according to implementation needs.
下面参考图12,其示出了适于用来实现本发明实施例的终端设备的计算机系统1200的结构示意图。图12示出的终端设备仅仅是一个示例,不应对本发明实施例的功能和使用范围带来任何限制。Referring to FIG. 12 below, it shows a schematic structural diagram of a
如图12所示,计算机系统1200包括中央处理单元(CPU)1201,其可以根据存储在只读存储器(ROM)1202中的程序或者从存储部分1208加载到随机访问存储器(RAM)1203中的程序而执行各种适当的动作和处理。在RAM 1203中,还存储有系统1200操作所需的各种程序和数据。CPU 1201、ROM 1202以及RAM 1203通过总线1204彼此相连。输入/输出(I/O)接口1205也连接至总线1204。As shown in FIG. 12, a
以下部件连接至I/O接口1205:包括键盘、鼠标等的输入部分1206;包括诸如阴极射线管(CRT)、液晶显示器(LCD)等以及扬声器等的输出部分1207;包括硬盘等的存储部分1208;以及包括诸如LAN卡、调制解调器等的网络接口卡的通信部分1209。通信部分1209经由诸如因特网的网络执行通信处理。驱动器1210也根据需要连接至I/O接口1205。可拆卸介质1211,诸如磁盘、光盘、磁光盘、半导体存储器等等,根据需要安装在驱动器1210上,以便于从其上读出的计算机程序根据需要被安装入存储部分1208。The following components are connected to the I/O interface 1205: an
特别地,根据本发明公开的实施例,上文参考流程图描述的过程可以被实现为计算机软件程序。例如,本发明公开的实施例包括一种计算机程序产品,其包括承载在计算机可读介质上的计算机程序,该计算机程序包含用于执行流程图所示的方法的程序代码。在这样的实施例中,该计算机程序可以通过通信部分1209从网络上被下载和安装,和/或从可拆卸介质1211被安装。在该计算机程序被中央处理单元(CPU)1201执行时,执行本发明的系统中限定的上述功能。In particular, the processes described above with reference to the flowcharts may be implemented as computer software programs in accordance with the disclosed embodiments of the present invention. For example, embodiments disclosed herein include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the method illustrated in the flowchart. In such an embodiment, the computer program may be downloaded and installed from the network via the
需要说明的是,本发明所示的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子可以包括但不限于:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本发明中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。而在本发明中,计算机可读的信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读的信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:无线、电线、光缆、RF等等,或者上述的任意合适的组合。It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the above two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus or device, or a combination of any of the above. More specific examples of computer readable storage media may include, but are not limited to, electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read only memory (ROM), erasable Programmable read only memory (EPROM or flash memory), fiber optics, portable compact disk read only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing. In the present invention, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, however, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code therein. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device . Program code embodied on a computer readable medium may be transmitted using any suitable medium including, but not limited to, wireless, wireline, optical fiber 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 that contains one or more logical functions for implementing the specified functions executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the blocks 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 is also noted that each block of the block diagrams or flowchart illustrations, and combinations of blocks in the block diagrams or flowchart illustrations, can be implemented in special purpose hardware-based systems that perform the specified functions or operations, or can be implemented using A combination of dedicated hardware and computer instructions is implemented.
描述于本发明实施例中所涉及到的模块可以通过软件的方式实现,也可以通过硬件的方式来实现。所描述的模块也可以设置在处理器中,例如,可以描述为:一种处理器包括加载模块、更新模块。其中,这些模块的名称在某种情况下并不构成对该模块本身的限定,例如,加载模块还可以被描述为“利用与应用唯一对应的自定义类加载器加载所述应用的模块”。The modules involved in the embodiments of the present invention may be implemented in a software manner, and may also be implemented in a hardware manner. The described modules can also be provided in the processor, for example, it can be described as: a processor includes a load module and an update module. The names of these modules do not constitute a limitation of the module itself under certain circumstances. For example, a loading module can also be described as "using a custom class loader uniquely corresponding to the application to load the module of the application".
作为另一方面,本发明还提供了一种计算机可读介质,该计算机可读介质可以是上述实施例中描述的设备中所包含的;也可以是单独存在,而未装配入该设备中。上述计算机可读介质承载有一个或者多个程序,当上述一个或者多个程序被一个该设备执行时,使得该设备包括:步骤S301.利用与应用一一对应的自定义类加载器加载所述应用的类文件;步骤S302.当所述应用中的配置更新后,使用新的自定义类加载器加载更新后的应用的类文件;将所述更新后的应用与所述新的类加载器一一对应。As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or may exist alone without being assembled into the device. The above-mentioned computer-readable medium carries one or more programs, and when the above-mentioned one or more programs are executed by a device, the device includes: Step S301. Use a custom class loader corresponding to an application to load the described class file of the application; Step S302. When the configuration in the application is updated, use a new custom class loader to load the class file of the updated application; combine the updated application with the new class loader One-to-one correspondence.
根据本发明实施例的技术方案,采用实时监控到所述应用中的配置,使用新的自定义类加载器加载更新后的应用;应用与类加载器一一对应的技术手段,能够方便部署中的应用动态修改文件并及时生效,优化热部署架构流程,增加可靠性,减少对IDE集成开发工具的依赖,不停服务来动态更新类。According to the technical solution of the embodiment of the present invention, the configuration in the application is monitored in real time, and a new custom class loader is used to load the updated application; the technical means of one-to-one correspondence between the application and the class loader can facilitate the deployment The application dynamically modifies the files and takes effect in time, optimizes the hot deployment architecture process, increases reliability, reduces the dependence on IDE integrated development tools, and dynamically updates classes without stopping services.
上述具体实施方式,并不构成对本发明保护范围的限制。本领域技术人员应该明白的是,取决于设计要求和其他因素,可以发生各种各样的修改、组合、子组合和替代。任何在本发明的精神和原则之内所作的修改、等同替换和改进等,均应包含在本发明保护范围之内。The above-mentioned specific embodiments do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims (16)
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 (15)
| 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 | 中国工商银行股份有限公司 | An 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 |
| CN113849189A (en) * | 2021-09-28 | 2021-12-28 | 上海金仕达软件科技有限公司 | Project hot deployment method and device |
| CN114047931A (en) * | 2021-11-15 | 2022-02-15 | 湖南快乐阳光互动娱乐传媒有限公司 | Script online method and development platform |
| CN114416530A (en) * | 2021-12-23 | 2022-04-29 | 金蝶医疗软件科技有限公司 | Bytecode modification method, apparatus, computer equipment and storage medium |
| CN116088909A (en) * | 2023-02-28 | 2023-05-09 | 上海中通吉网络技术有限公司 | Method, system, equipment and storage medium for realizing configuration hot deployment |
| CN117850818A (en) * | 2023-12-29 | 2024-04-09 | 中国邮政储蓄银行股份有限公司 | Hot deployment method of remote server, remote server and hot deployment system |
| CN118192984A (en) * | 2024-03-21 | 2024-06-14 | 山东中创软件商用中间件股份有限公司 | Class loading method, device, equipment and storage medium in page compilation stage |
| CN120215996A (en) * | 2025-05-28 | 2025-06-27 | 杭州新中大科技股份有限公司 | Java program dynamic updating method, device, equipment, medium and product |
| CN121300810A (en) * | 2025-12-15 | 2026-01-09 | 企家有道网络技术(北京)有限公司 | A method, apparatus, electronic device, and storage medium for hot code deployment. |
Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20100199259A1 (en) * | 2009-01-30 | 2010-08-05 | Quinn Timothy J | Methods and Apparatus for Dynamic Class Reloading and Versioning |
| CN102122263A (en) * | 2011-03-23 | 2011-07-13 | 成都勤智数码科技有限公司 | A JAVA application system runtime monitoring method and device |
| CN102402427A (en) * | 2010-09-09 | 2012-04-04 | 阿里巴巴集团控股有限公司 | Method and device for updating Java application program |
| CN102929597A (en) * | 2012-09-24 | 2013-02-13 | 摩卡软件(天津)有限公司 | Java-platform-based web service support method and device |
-
2018
- 2018-07-12 CN CN201810764468.6A patent/CN110716720A/en active Pending
Patent Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20100199259A1 (en) * | 2009-01-30 | 2010-08-05 | Quinn Timothy J | Methods and Apparatus for Dynamic Class Reloading and Versioning |
| CN102402427A (en) * | 2010-09-09 | 2012-04-04 | 阿里巴巴集团控股有限公司 | Method and device for updating Java application program |
| CN102122263A (en) * | 2011-03-23 | 2011-07-13 | 成都勤智数码科技有限公司 | A JAVA application system runtime monitoring method and device |
| CN102929597A (en) * | 2012-09-24 | 2013-02-13 | 摩卡软件(天津)有限公司 | Java-platform-based web service support method and device |
Non-Patent Citations (1)
| Title |
|---|
| ZEJIAN_: "深入理解Java类加载器(ClassLoader)", Retrieved from the Internet <URL:http://blog.csdn.net/javazejian/article/details/73413292> * |
Cited By (20)
| 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 |
| CN111538545B (en) * | 2020-04-23 | 2024-07-12 | 京东方科技集团股份有限公司 | Java application running method, device, medium and electronic device |
| CN111538545A (en) * | 2020-04-23 | 2020-08-14 | 京东方科技集团股份有限公司 | Java application running method, device, medium and electronic equipment |
| CN112463194B (en) * | 2020-11-30 | 2023-12-15 | 深圳市优必选科技股份有限公司 | File data compatible method and device, terminal equipment and storage medium |
| 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 |
| CN112764827B (en) * | 2020-12-31 | 2023-04-07 | 重庆广播电视大学重庆工商职业学院 | Java class hot loading method with safety verification |
| CN112835865A (en) * | 2021-03-31 | 2021-05-25 | 中国工商银行股份有限公司 | An application hot deployment system, method and device |
| CN113849189A (en) * | 2021-09-28 | 2021-12-28 | 上海金仕达软件科技有限公司 | Project hot deployment method and device |
| CN114047931A (en) * | 2021-11-15 | 2022-02-15 | 湖南快乐阳光互动娱乐传媒有限公司 | Script online method and development platform |
| CN114047931B (en) * | 2021-11-15 | 2025-03-18 | 湖南快乐阳光互动娱乐传媒有限公司 | A script online method and development platform |
| CN114416530A (en) * | 2021-12-23 | 2022-04-29 | 金蝶医疗软件科技有限公司 | Bytecode modification method, apparatus, computer equipment and storage medium |
| CN116088909A (en) * | 2023-02-28 | 2023-05-09 | 上海中通吉网络技术有限公司 | Method, system, equipment and storage medium for realizing configuration hot deployment |
| CN117850818A (en) * | 2023-12-29 | 2024-04-09 | 中国邮政储蓄银行股份有限公司 | Hot deployment method of remote server, remote server and hot deployment system |
| CN118192984A (en) * | 2024-03-21 | 2024-06-14 | 山东中创软件商用中间件股份有限公司 | Class loading method, device, equipment and storage medium in page compilation stage |
| CN118192984B (en) * | 2024-03-21 | 2025-07-29 | 山东中创软件商用中间件股份有限公司 | Class loading method, device, equipment and storage medium of page compiling stage |
| CN120215996A (en) * | 2025-05-28 | 2025-06-27 | 杭州新中大科技股份有限公司 | Java program dynamic updating method, device, equipment, medium and product |
| CN121300810A (en) * | 2025-12-15 | 2026-01-09 | 企家有道网络技术(北京)有限公司 | A method, apparatus, electronic device, and storage medium for hot code deployment. |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN110716720A (en) | Method and device for realizing application hot deployment | |
| US8904368B2 (en) | Instantiating a composite application for different target platforms | |
| US9852015B2 (en) | Automatic discovery of a JavaScript API | |
| US9830135B2 (en) | Declarative and pluggable business logic for systems management | |
| US8239839B2 (en) | Asynchrony debugging using web services interface | |
| US10656971B2 (en) | Agile framework for vertical application development and delivery | |
| US9529648B2 (en) | Generic declaration of bindings between events and event handlers regardless of runtime structure | |
| US9218100B2 (en) | Method and system for partitioning asset management plugins | |
| WO2020063252A1 (en) | Method and device for isolating multiple version dependency | |
| US20150220308A1 (en) | Model-based development | |
| CN109308241B (en) | Method, device, terminal device and storage medium for monitoring application startup process | |
| US9459859B2 (en) | Template derivation for configuration object management | |
| CN103176892B (en) | A kind of page monitoring method and system | |
| US20150220327A1 (en) | Extensible data model and service for infrastructure management | |
| CN108228147A (en) | A kind of performance data journal obtaining method and device | |
| US9491266B2 (en) | Representational state transfer communications via remote function calls | |
| CN104317591A (en) | OSGi (open service gateway initiative)-based web interface frame system and web business processing method thereof | |
| CN110569050A (en) | A small program update method and device | |
| US20230169138A1 (en) | Rendering primitive child elements corresponding to child components of a user interface without instantiating the child components | |
| US9626251B2 (en) | Undo configuration transactional compensation | |
| CN108845864B (en) | Spring frame-based JVM garbage recycling method and device | |
| CN113778388A (en) | Program development method and apparatus | |
| CN107608672A (en) | A kind of UI module managements, UI module management methods and system | |
| US11809861B2 (en) | Development environment organizer with enhanced state switching and sharing | |
| US20070130152A1 (en) | Method, apparatus, and program product for building integration workflow endpoints into web components |
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 | ||
| RJ01 | Rejection of invention patent application after publication |
Application publication date: 20200121 |
|
| RJ01 | Rejection of invention patent application after publication |