[go: up one dir, main page]

CN102073525B - Based on dynamic update method and the device of the Web service system of Java platform - Google Patents

Based on dynamic update method and the device of the Web service system of Java platform Download PDF

Info

Publication number
CN102073525B
CN102073525B CN201110023443.9A CN201110023443A CN102073525B CN 102073525 B CN102073525 B CN 102073525B CN 201110023443 A CN201110023443 A CN 201110023443A CN 102073525 B CN102073525 B CN 102073525B
Authority
CN
China
Prior art keywords
classloader
built
newly
class file
java
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.)
Active
Application number
CN201110023443.9A
Other languages
Chinese (zh)
Other versions
CN102073525A (en
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.)
ZTE Corp
Original Assignee
ZTE Corp
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 ZTE Corp filed Critical ZTE Corp
Priority to CN201110023443.9A priority Critical patent/CN102073525B/en
Publication of CN102073525A publication Critical patent/CN102073525A/en
Application granted granted Critical
Publication of CN102073525B publication Critical patent/CN102073525B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Stored Programmes (AREA)

Abstract

The present invention relates to computer realm, disclose a kind of Web service system dynamic update method based on Java platform and device, in order under the prerequisite of not interrupting Web service, realize the dynamic update of Web service system.The method is: adopt self-defining Classloader to load the java class file of assigned address, and adopt the Classloader after loading java class file to replace the Classloader of specifying in Java platform kernel, like this, the java class file after upgrading can be adopted directly to replace original java class file, thus achieve the dynamic update of Web service system, do not need to restart Web server, do not need to interrupt Web service service yet, thus ensure that the continuity of Web service, improve performance and the service quality of Web service system.

Description

Based on dynamic update method and the device of the Web service system of Java platform
Technical field
The present invention relates to computer realm, particularly a kind of dynamic update method of the Web service system based on Java platform and device.
Background technology
Along with the continuous renewal of Web technology, the Web service system based on different framework emerges in an endless stream, because Java language has cross-platform advantage, make the Web service system application based on J2EE more extensive, almost spread all trades and professions, such as, telecommunications industry, financial industry etc.Business demand change is frequent, usually need Web service system 24 hours persistent services, and in time carrying out system upgrade, then need to stop Web service system, this will certainly interrupt the business operation that active user carries out, and can affect to the normal operation of Web service system.
In view of this drawback and limitation, just need the dynamic update realizing Web service system based on J2EE, namely in Web container, the heat realizing java class file loads.
Summary of the invention
The embodiment of the present invention provides a kind of Web service system dynamic update method based on Java platform and device, in order under the prerequisite of not interrupting Web service, realizes the dynamic update of Web service system.
The concrete technical scheme that the embodiment of the present invention provides is as follows:
Based on a Web service system dynamic update method for Java platform, comprising:
A newly-built self-defining Classloader, makes newly-built Classloader inherit the parent loader of specifying, and described parent loader is set to null value;
Described newly-built Classloader is adopted to load at least one java class file at preset memory locations;
The Classloader after loading java class file is adopted to replace the Classloader loaded of specifying in Java platform kernel.
Based on a Web service system dynamic update device for Java platform, comprising:
Set up unit, for a newly-built self-defining Classloader, make newly-built Classloader inherit the parent loader of specifying, and described parent loader is set to null value;
First loading unit, loads at least one java class file for adopting described newly-built Classloader at preset memory locations;
Second loading unit, adopts the Classloader after loading java class file to replace other Classloaders of specifying in Java platform kernel.
In the embodiment of the present invention, managerial personnel only need to adopt self-defining Classloader to load the java class file of assigned address, and adopt the Classloader after loading java class file to replace the Classloader of specifying in Java platform kernel, the java class file after upgrading can be adopted directly to replace original java class file, thus achieve the dynamic update of Web service system, do not need to restart Web server, do not need to interrupt Web service service yet, thus ensure that the continuity of Web service, improve performance and the service quality of Web service system.
Accompanying drawing explanation
Fig. 1 is java class loader hierarchical chart in the present invention under prior art;
Fig. 2 is java class loader workflow schematic diagram under prior art;
Fig. 3 A realizes java class file heat to load process flow diagram in the embodiment of the present invention;
Fig. 3 B is self-defined DynamincClassLoader structural representation in the embodiment of the present invention;
Fig. 4 is Web server illustrative view of functional configuration in the embodiment of the present invention.
Embodiment
Based on the dynamic update process of the Web service system of Java platform, namely be the hot replacement process of the java class file run in Web service system, in the embodiment of the present invention, rewrite kind loading method, namely the load mode of java class file has been redefined, realize java class file (as, Jar wrap) dynamic load, be specially: a newly-built self-defining Classloader, newly-built Classloader is made to inherit the parent loader of specifying, and this parent loader is set to null value, newly-built Classloader is adopted to load at least one java class file at preset memory locations again, and adopt the Classloader after loading java class file to replace the Classloader loaded of specifying in Java platform kernel.
Below in conjunction with accompanying drawing, the preferred embodiment of the present invention is described in detail.
Based in the Web service system of Java platform, all java class files are when loading, be all realize loading work by built-in Classloader (ClassLoader), ClassLoader loading procedure itself has certain level and relation.Consult shown in Fig. 1, with BootStrapClassLoader, ExtClassLoader, AppClassLoader and user-defined CustomClassLoader, these four kinds of Classloaders are example, these four kinds of Classloaders are responsible for the loading of the java class file in different path respectively, and define the hierarchical structure of a Classloader:
BootStrapClassLoader is in the top of Classloader hierarchical structure, be responsible for the loading of java class file under Sun.boot.class.path path, be defaulted as the java class file that Core API (application programming interfaces) under jre/lib catalogue or-Xbootclasspath option are specified.
ExtClassLoader is in time high level of Classloader hierarchical structure, is responsible for the loading of the java class file under java.ext.dirs path, is defaulted as the java class file under jre/lib/ext catalogue or-Djava.ext.dirs assigned catalogue;
AppClassLoader is in the secondary low layer of Classloader hierarchical structure, and under responsible java.class.path, the loading of java class file, is defaulted as the value set in environmental variance CLASSPATH.
User Defined CustomClassLoader is in the lowermost layer of Classloader hierarchical structure, can need the class loading procedure customizing oneself according to user, carries out specifying the dynamic realtime of java class file to load in the runtime.
Consult shown in Fig. 2, above-mentioned four kinds of Classloaders form certain set membership, high level is father's loader of low layer, when carrying out the loading of java class file, first system bottom-uply in Classloader level result can check whether the java class file being loaded with and having specified in turn, if loaded, directly return quoting of this java class file, toply the java class file of specifying was not loaded yet if be checked through, so system can top-downly attempt loading the java class file of specifying one by one, until retrieve user-defined Classloader CustomClassLoader, if can't load successfully, just there will be exception.
Same class loader example, the java class file that name is identical can only exist one, and only can load once, and no matter whether this java class file changes, when needing again next time to load, can only directly return quoting of the java class file loaded from the buffer memory of self.
Based on above-mentioned principle, consult shown in Fig. 3 A, in the embodiment of the present invention, the detailed process realizing the loading of java class file heat is as follows:
Step 300: a newly-built self-defining Classloader.
Consult shown in Fig. 3 B, in the present embodiment, by newly-built self-defining Classloader called after DynamicClassLoader.
Step 310: make newly-built Classloader inherit the parent loader of specifying, and parent loader is set to null value, i.e. null value.
So-called succession, refer to and set up new Classloader based on the method and attribute that are comprised by already present Classloader, newly-established class loads all method and attribute that heritable Classloader can be used to comprise, new method and attribute can also be expanded, adopt this technology of succession that multiplexing code is in the past very easy to, greatly can shorten the construction cycle, reduce development cost.
Consult shown in Fig. 3 B, in the present embodiment, the parent loader of specifying that DynamicClassLoader inherits is CustomClassLoader, and the value of CustomClassLoade is set to null value, like this, original loading sequence can be changed, namely originally java class file is first loaded by parent loader, Java file is loaded again by subclass loader, change into and first load java class file by sub-loader, load java class file by parent loader again, thus the amendment of original class loading sequence is become self-defining class loading sequence.
Step 320: adopt newly-built Classloader to load at least one java class file of designated storage location.
In the present embodiment, when performing step 320, comprising:
The load path of newly-built Classloader is set to self-defining store path, judges whether that such loaded, this needs by calling findLoadedClass method to realize;
By newly-built Classloader instantiation, this needs by calling defineClass method to realize, and the class bytecode usually will represented with byte arrays, converts Class example to, thus completes the instantiation of Classloader; The code calling defineClass method is as follows:
privateClassinstantiateClass(Stringname,InputStreamfin,longlen){
byte[]raw=newbyte[(int)len];
fin.read(raw);
fin.close();
returndefineClass(name,raw,0,raw.length);
}
Arrange the loading behavior of newly-built Classloader, at least one the java class file making newly-built Classloader load on self-defining store path this store path is preserved, this needs by calling resolveClass method to realize.
Newly-built Classloader after running example, thus the loading realizing the java class file on the store path of specifying, this needs to realize by rewriteeing loadClass method, and the code rewriteeing loadClass method is as follows:
protectedClassloadClass(Stringname,booleanresolve)
throwsClassNotFoundException{
Classcls=null;
cls=findLoadedClass(name);
if(!this.dynaclazns.contains(name)&&cls==null)
cls=getSystemClassLoader().loadClass(name);
if(cls==null)
thrownewClassNotFoundException(name);
if(resolve)
resolveClass(cls);
returncls;
}
Step 330: adopt the Classloader after loading java class file to replace the Classloader loaded of specifying in Java platform kernel.
When performing step 330, need the class load mode of the Java platform changed in Web server, make Web server by the heavily loaded Java platform kernel extremely of Classloader after loading java class file, replace the Classloader loaded of specifying in Java platform kernel, thus the heat completing java class file is replaced.
The Java platform that each Web server runs has self class load mode, TomcatServer for Web server, structure Classloader is set when startup by TomcatServer, suppose that its level and relation are BootStrapClassLoader-> SystemClassLoader-> CommonClassLoader-> CatalinaClassLoader-> SharedClassLoader-> web application WebappXClassLoader (for loading the Classloader of web application) respectively.
BootStrapClassLoader, for loading basic class file working time that Java platform provides, add all java class files and resource in the jar file that SystemExtensions catalogue (JAVA_HOME/jre/lib/ext) is inner;
SystemClassLoader, for loading java class file and the resource of CLASSPATH environmental variance configuration path;
CommonClassLoader, applies the java class file that can search, namely also with regard to the java class file below common catalogue and resource for loading Tomcat server itself with all Web;
CatalinaClassLoader, for loading all unpacked java class file and resource in $ CATALINA_HOME/server/classes;
SharedClassLoader, for loading all java class files packed in $ CATALINA_BASE/shared/classes and resource;
WebappXClassLoader, a kind of web application loading classes, for being carried in/WEB-INF/classes catalogue in all unpacked java classs and resource, a WebappXClassLoader is created to the Web application in each TomcatServer, WEB-INF/classes under Web application, WEB-INF/lib is loaded by WebappXClassLoader, and the Web application of the java class file that it loads to other is sightless.As, the application component of a certain operation system and bag (being made up of multiple class file) be mounted in/WEB-INF/classes and WEB-INF/lib below, and WebappXClassLoader is responsible for all application components of this operation system and the loading of bag.
From the above, want the class load mode changing Java platform on Web server, just need the load mode transforming WebappXClassLoader, namely transform the webappClassLoader class of TomcatServer, concrete step is as follows:
By the newly-built Classloader DynamicClassLoader being loaded with java class file, as the member property of webappClassLoader;
Add method for reconstructing, make TomcatServer when reloading, adopt the Classloader DynamicClassLoader of heavy duty, replace in Java platform kernel the Classloader loaded of specifying, like this, just can carry out heat for any one java class file to replace, code is as follows:
publicvoidreCreateDynamicClassLoader(){
dynamicClassLoader=newDynamicClassLoader(this);
}
Amendment findClass method, because skin upgrading class component needs the findClass method called in webappClassLoader class to realize dynamic update class component, and findClass method acquiescence can not be accessed by outer category, so the attribute key word before amendment findClass method, findClass method attribute modification is become public, add relevant code, thus the attribute of reconstruction is added relevant place.
Idiographic flow is: in Tomcat kernel, opens the amendment of webappClassLoader.java class file:
At the 832nd row (being only citing), open findClass method
publicClassfindClass(Stringname)throwsClassNotFoundException{
1569th row (being only citing), adds following line code.
if(isReload)removeResourceEntry(name);
1577th row (being only citing),
if((entry==null)||(entry.binaryContent==null))
Change into
if((entry==null)||(entry.loadedClass==null&&entry.binaryContent==null))
1633rd ~ 1636 row (being only citing)
if(entry.loadedClass==null){
clazz=defineClass(name,entry.binaryContent,0,entry.binaryContent.length,codeSource);
Change into
byte[]classData=newbyte[entry.binaryContent.length];
System.arraycopy(entry.binaryContent,0,classData,0,classData.length);
if(entry.loadedClass==null){
clazz=isReload?dynamicClassLoader.loadClass(name,classData,codeSource):defineClass(name,classData,0,classData.length,codeSource);
Based on above-described embodiment, consult shown in Fig. 4, the Web server based on Java platform comprises sets up unit 40, first loading unit 41 and the second loading unit 42, wherein,
Set up unit 40, for a newly-built self-defining Classloader, make newly-built Classloader inherit the parent loader of specifying, and this parent loader is set to null value;
First loading unit 41, loads at least one java class file for adopting newly-built Classloader at preset memory locations;
Second loading unit 42, adopts the Classloader after loading java class file to replace other Classloaders of specifying in Java platform kernel.
In sum, in the embodiment of the present invention, managerial personnel only need to adopt self-defining Classloader to load the java class file of assigned address, and adopt the Classloader after loading java class file to replace the Classloader of specifying in Java platform kernel, the java class file after upgrading can be adopted directly to replace original java class file, thus achieve the dynamic update of Web service system, do not need to restart Web server, do not need to interrupt Web service service yet, thus ensure that the continuity of Web service, improve performance and the service quality of Web service system.
Obviously, those skilled in the art can carry out various change and modification to the present invention and not depart from the spirit and scope of the present invention.Like this, if these amendments of the present invention and modification belong within the scope of the claims in the present invention and equivalent technologies thereof, then the present invention is also intended to comprise these change and modification.

Claims (6)

1., based on a Web service system dynamic update method for Java platform, it is characterized in that, comprising:
A newly-built self-defining Classloader, makes newly-built Classloader inherit the parent loader of specifying, and described parent loader is set to null value;
Described newly-built Classloader is adopted to load at least one java class file at preset memory locations;
Classloader after described loading java class file is set to the member property of WebappXClassLoader;
Classloader after described loading java class file is loaded in Java platform kernel, replaces the Classloader loaded of specifying in Java platform kernel.
2. the method for claim 1, is characterized in that, adopts described newly-built Classloader to load at least one java class file at preset memory locations, comprising:
The load path of newly-built Classloader is set to self-defining store path;
By described newly-built Classloader instantiation;
The loading behavior of described newly-built Classloader is set, the java class file making described Classloader be carried in self-defining store path is preserved;
Newly-built Classloader after running example.
3. the method for claim 1, is characterized in that, the parent loader of specifying that described newly-built Classloader is inherited is CustomClassLoader.
4., based on a Web service system dynamic update device for Java platform, it is characterized in that, comprising:
Set up unit, for a newly-built self-defining Classloader, make newly-built Classloader inherit the parent loader of specifying, and described parent loader is set to null value;
First loading unit, loads at least one java class file for adopting described newly-built Classloader at preset memory locations;
Second loading unit, for being set to the member property of WebappXClassLoader by the Classloader after described loading java class file; Classloader after described loading java class file is loaded in Java platform kernel, replaces the Classloader loaded of specifying in Java platform kernel.
5. device as claimed in claim 4, is characterized in that, described first loading unit adopts described newly-built Classloader to load at least one java class file at preset memory locations, comprising:
The load path of newly-built Classloader is set to self-defining store path;
By described newly-built Classloader instantiation;
The loading behavior of described newly-built Classloader is set, the java class file making described Classloader be carried in self-defining store path is preserved;
Newly-built Classloader after running example.
6. device as claimed in claim 4, it is characterized in that, described unit of setting up makes newly-built Classloader inherit the parent loader of specifying, and comprising: make newly-built Classloader inherit CustomClassLoader.
CN201110023443.9A 2011-01-20 2011-01-20 Based on dynamic update method and the device of the Web service system of Java platform Active CN102073525B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201110023443.9A CN102073525B (en) 2011-01-20 2011-01-20 Based on dynamic update method and the device of the Web service system of Java platform

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201110023443.9A CN102073525B (en) 2011-01-20 2011-01-20 Based on dynamic update method and the device of the Web service system of Java platform

Publications (2)

Publication Number Publication Date
CN102073525A CN102073525A (en) 2011-05-25
CN102073525B true CN102073525B (en) 2016-03-02

Family

ID=44032071

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201110023443.9A Active CN102073525B (en) 2011-01-20 2011-01-20 Based on dynamic update method and the device of the Web service system of Java platform

Country Status (1)

Country Link
CN (1) CN102073525B (en)

Families Citing this family (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102421113B (en) * 2011-11-28 2018-05-04 中兴通讯股份有限公司 Embedded multiple LMT realize the method and device of multi-site operation in centralized network management
CN103186400B (en) * 2011-12-31 2016-01-13 深圳市金蝶中间件有限公司 Web application upgrade method and system
CN102880490B (en) * 2012-09-19 2016-03-02 南京大学 A kind of time delay dynamic object update method based on Java Virtual Machine
CN102929597B (en) * 2012-09-24 2016-03-09 摩卡软件(天津)有限公司 A kind of Web service based on Java platform supports method and apparatus
CN104102502B (en) * 2013-04-09 2018-09-04 腾讯科技(深圳)有限公司 A kind of processing method that realizing heat deployment, device and server
CN103793248B (en) * 2014-01-23 2017-02-01 北京奇虎科技有限公司 Method and device for upgrading application program
CN105045642B (en) * 2015-08-31 2018-09-25 北京金山安全软件有限公司 Method and device for loading self-defined classes
CN106708494B (en) * 2015-11-18 2020-11-27 北京神州泰岳软件股份有限公司 JAR upgrading method and device
CN109933356B (en) * 2019-03-26 2022-06-03 杭州云毅网络科技有限公司 Remote proxy hot replacement method and device
CN110532037A (en) * 2019-08-16 2019-12-03 杭州云徙科技有限公司 A Java running method, system and terminal
CN111625256B (en) * 2020-05-15 2024-02-09 广东浪潮大数据研究有限公司 Application program upgrading method, system, equipment and computer storage medium
CN112764827B (en) * 2020-12-31 2023-04-07 重庆广播电视大学重庆工商职业学院 Java class hot loading method with safety verification

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101126988A (en) * 2007-10-11 2008-02-20 金蝶软件(中国)有限公司 Class file loading method and system

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6915511B2 (en) * 2001-05-22 2005-07-05 Sun Microsystems, Inc. Dynamic class reloading mechanism
US7073171B2 (en) * 2003-02-28 2006-07-04 Bea Systems, Inc. EJB implementation class loading with removed dependencies with ability to replace EJB implementation class without full redeployment

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101126988A (en) * 2007-10-11 2008-02-20 金蝶软件(中国)有限公司 Class file loading method and system

Also Published As

Publication number Publication date
CN102073525A (en) 2011-05-25

Similar Documents

Publication Publication Date Title
CN102073525B (en) Based on dynamic update method and the device of the Web service system of Java platform
CN102929597B (en) A kind of Web service based on Java platform supports method and apparatus
US10795660B1 (en) Live code updates
US8332835B2 (en) Method and system for automated code-source indexing in java virtual machine environment
US6298353B1 (en) Checking serialization compatibility between versions of java classes
US7849459B2 (en) Deploying java applications in resource constrained environments
CN109491695A (en) A kind of increment updating method of integrated Android application
KR20050061380A (en) Self-describing software image update components
EP1224543A2 (en) FIXING INCOMPATIBLE APPLICATIONS BY PROVIDING STUBS FOR APIs
US8954461B2 (en) Systems and methods for object to relational mapping extensions
US20090007081A1 (en) System and Method of Generating Applications for Mobile Devices
CN100549957C (en) One kind is loaded the method and a kind of isolating and is loaded the device of isolating
CN102193806B (en) Upgrade the method and apparatus of animation
US9053134B2 (en) View variants in database schema mapping
CN100365568C (en) Method for realizing plug-in function under Java applet
US20080168079A1 (en) Extending Native Data Types
CN104731622B (en) Application program loading method, device and mobile terminal
CN112685020A (en) Method and device for dynamically creating service interface, electronic equipment and storage medium
CN103154891B (en) Virtual machine stage detects
US20230325158A1 (en) Extending application lifecycle management to user-created application platform components
CN106406828A (en) Method and apparatus for modifying business tool function of JAVA system
CN101145164B (en) Chronological book inquiry method and device
CN103631971A (en) Recombining method and device for transplantable executive file
CN101002174A (en) Method for loading software with an intermediate object oriented language in a portable device
CN103309696A (en) Method and device for updating Java card extended library, and Java card

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant