CN106354533B - A kind of module dynamic loading method and device - Google Patents

A kind of module dynamic loading method and device Download PDF

Info

Publication number
CN106354533B
CN106354533B CN201610757151.0A CN201610757151A CN106354533B CN 106354533 B CN106354533 B CN 106354533B CN 201610757151 A CN201610757151 A CN 201610757151A CN 106354533 B CN106354533 B CN 106354533B
Authority
CN
China
Prior art keywords
service object
servlet
module
servlet service
new
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
CN201610757151.0A
Other languages
Chinese (zh)
Other versions
CN106354533A (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.)
Beijing Forever Technology Co Ltd
Original Assignee
Beijing Forever Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Forever Technology Co Ltd filed Critical Beijing Forever Technology Co Ltd
Priority to CN201610757151.0A priority Critical patent/CN106354533B/en
Publication of CN106354533A publication Critical patent/CN106354533A/en
Application granted granted Critical
Publication of CN106354533B publication Critical patent/CN106354533B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading

Abstract

The invention discloses a kind of module dynamic loading method and devices, when needing dynamically load application module, construct a new servlet service object, when receiving servlet request, the servlet received request is transmitted to new servlet service object using original servlet service object, to realize the dynamically load of application modules by new servlet service object, and after the completion of new service object's building, the servlet service object that is constructed when destroying last module dynamically load.Using method disclosed by the invention without rebuilding project framework, in each dynamically load application module, new servlet service object need to only be constructed, therefore, the present invention realizes the dynamically load that can be still realized in the case where keeping project framework constant to module, it is not only easy to realize, and learning cost is low, the manpower of consuming and time are less.

Description

A kind of module dynamic loading method and device
Technical field
The present invention relates to module loading technical fields, more specifically, being related to a kind of module dynamic loading method and device.
Background technique
In java web application, the B/S that usually there are many needs long lasting for operation is applied, these are applied sometimes It may require that and add or delete some application modules, at this moment just need do not stopping answering to realize using module Dynamic loading technique In the case where, application module is dynamically added or deleted.
Currently, common module Dynamic loading technique is OSGi technology, OSGi technology is Java mobilism modular system A series of specifications and technology based on the specification realize, be the module Dynamic loading technique in a kind of more fine granularity.Although The dynamically load of application modules may be implemented in OSGi technology, but does not use OSGi technology when a project is in framework, And when increasing module dynamically load demand (such as dynamically load demand to MVC module) in project development process, it may It just needs to rebuild project framework.Due to OSGi technology complexity with higher, it is inevitable to rebuild project framework It will lead to learning cost increase, and can also expend more manpower and time.
To sum up, a kind of module dynamic loading method and system how are provided, to realize in the feelings for keeping project framework constant It can still realize that the dynamically load of module be those skilled in the art's technical problem urgently to be resolved under condition.
Summary of the invention
In view of this, the present invention discloses a kind of module dynamic loading method and device, project framework is being kept not to realize The dynamically load to module can be still realized in the case where change.
A kind of module dynamic loading method, comprising:
When needing dynamically load application module, a new servlet service object is constructed;
When receiving servlet request, servlet request is sent to original servlet service object;
Servlet request the new servlet is transmitted to using the original servlet service object to take Business object is handled, to realize the dynamically load to the application module by the new servlet service object;
After the completion of the new servlet service object building, constructed when destroying last module dynamically load Servlet service object.
Preferably, described when needing dynamically load application module, one new servlet service object of building includes:
When needing dynamically load application module, obtaining the application module needs all resources to be loaded;
Classloader ClassLoader predetermined is constructed using all resources;
The initial method for calling spring Request dispatcher, construct to the resource in the ClassLoader To the new servlet service object;
The address of the new servlet service object is saved into the original servlet service object.
Preferably, described to include: using all resources constructions Classloader ClassLoader predetermined
All resources are divided into fixed class resource and variation class resource;
The fixed class resource is constructed to obtain father using uniform resource locator loader URLClassLoader Loader;
Using father's loader as parent, the variation class resource is constructed using the URLClassLoader Obtain sub- loader, wherein father's loader and the sub- loader constitute the ClassLoader.
Preferably, it is described servlet request is transmitted to using the original servlet service object it is described new Servlet service object handle, the application module is moved with being realized by the new servlet service object State loads
Judge to whether there is the request for belonging to same kind but adhering to different ClassLoader separately in the servlet request;
The request if it exists then replicates the attribute in corresponding first request entity of the request, obtains institute State the duplication attribute of the first request entity;
According to the resource in the duplication attribute and ClassLoader predetermined, the second request entity is obtained, wherein The resource is that the application module needs all resources to be loaded;
Second request entity is transmitted to the new servlet using the original servlet service object Service object is handled, to realize the dynamically load to the application module by the new servlet service object.
Preferably, described after the completion of the new servlet service object building, destroy last module dynamically load When the process of servlet service object that constructs include:
After the completion of the new servlet service object building, constructed when destroying the last module dynamically load Servlet service object in resource in network application container, and the network application container is set to sky;
The resource in servlet service object's neutron loader constructed when destroying the last module dynamically load, And the sub- loader is set to sky;
The servlet service object constructed when destroying the last module dynamically load.
Preferably, it after the servlet service object constructed when destroying the upper primary module dynamically load, also wraps It includes:
Servlet service pair using system rubbish recovering method to being constructed when destroying the last module dynamically load The rubbish generated as during is recycled.
A kind of module dynamic loading device, comprising:
Construction unit, for constructing a new servlet service object when needing dynamically load application module;
Transmission unit, for servlet request being sent to original when receiving servlet request Servlet service object;
Retransmission unit, it is described for being transmitted to servlet request using the original servlet service object New servlet service object is handled, to be realized by the new servlet service object to the application module Dynamically load;
Unit is destroyed, after the completion of working as the new servlet service object building, last module dynamic is destroyed and adds The servlet service object constructed when load.
Preferably, the construction unit includes:
Subelement is obtained, needs institute to be loaded for when needing dynamically load application module, obtaining the application module There is resource;
Subelement is constructed, for constructing Classloader ClassLoader predetermined using all resources;
Subelement is instantiated, for calling the initial method of spring Request dispatcher, in the ClassLoader Resource constructed to obtain the new servlet service object;
Saving subunit, for saving the address of the new servlet service object to the original servlet In service object.
Preferably, the construction subelement includes:
Resource category divides subelement, for all resources to be divided into fixed class resource and variation class resource;
Father's loader constructs subelement, for utilizing uniform resource locator loader URLClassLoader to described solid Determine class resource to be constructed to obtain father's loader;
Sub- loader constructs subelement, for utilizing the URLClassLoader using father's loader as parent The variation class resource is constructed to obtain sub- loader, wherein described in father's loader and the sub- loader composition ClassLoader。
Preferably, the retransmission unit includes:
Judgment sub-unit, for judging in servlet request with the presence or absence of belonging to same kind but adhere to difference separately The request of ClassLoader;
Subelement is replicated, in the case where the judgment sub-unit is judged as YES, then corresponding to the request the Attribute in one request entity is replicated, and the duplication attribute of first request entity is obtained;
Second request entity obtains subelement, for according in the duplication attribute and ClassLoader predetermined Resource, the second request entity is obtained, wherein the resource is that the application module needs all resources to be loaded;
Subelement is forwarded, for being transmitted to second request entity using the original servlet service object The new servlet service object is handled, and applies mould to described to realize by the new servlet service object The dynamically load of block.
Preferably, the destruction unit includes:
First destroys subelement, for destroying the last time after the completion of the new servlet service object building Resource in the servlet service object constructed when module dynamically load in network application container, and the network application is held Device is set to sky;
Second destroys subelement, the servlet service object constructed when for destroying the last module dynamically load Resource in neutron loader, and the sub- loader is set to sky;
Third destroys subelement, the servlet service object constructed when for destroying the last module dynamically load.
Preferably, further includes:
Garbage reclamation subelement, the servlet service pair for being constructed when destroying the upper primary module dynamically load Servlet service pair as later, using system rubbish recovering method to being constructed when destroying the last module dynamically load The rubbish generated as during is recycled.
It is dynamic when needing from above-mentioned technical solution it is found that the invention discloses a kind of module dynamic loading method and device When state loads application module, a new servlet service object is constructed, when receiving servlet request, using original The servlet received request is transmitted to new servlet service object by servlet service object, to pass through newly Servlet service object realizes the dynamically load of application modules, and after the completion of new service object's building, destroys last The servlet service object constructed when module dynamically load.It follows that using method disclosed by the invention without rebuilding Project framework only need to construct new servlet service object in each dynamically load application module, therefore, the present invention The dynamically load that can be still realized in the case where keeping project framework constant to module is realized, is not only easy to realize, and is learnt At low cost, the manpower of consuming and time are less.
Detailed description of the invention
In order to more clearly explain the embodiment of the invention or the technical proposal in the existing technology, to embodiment or will show below There is attached drawing needed in technical description to be briefly described, it should be apparent that, the accompanying drawings in the following description is only this The embodiment of invention for those of ordinary skill in the art without creative efforts, can also basis Disclosed attached drawing obtains other attached drawings.
Fig. 1 is a kind of method flow diagram of module dynamic loading method disclosed by the embodiments of the present invention;
Fig. 2 is a kind of method flow diagram for constructing new servlet service object disclosed by the embodiments of the present invention;
Fig. 3 is a kind of method flow diagram for destroying original servlet service object disclosed by the embodiments of the present invention;
Fig. 4 is a kind of structural schematic diagram of module dynamic loading device disclosed by the embodiments of the present invention;
Fig. 5 is a kind of structural schematic diagram of construction unit disclosed by the embodiments of the present invention;
Fig. 6 is a kind of structural schematic diagram of construction unit disclosed by the embodiments of the present invention.
Specific embodiment
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete Site preparation description, it is clear that described embodiments are only a part of the embodiments of the present invention, instead of all the embodiments.It is based on Embodiment in the present invention, it is obtained by those of ordinary skill in the art without making creative efforts every other Embodiment shall fall within the protection scope of the present invention.
The embodiment of the invention discloses a kind of module dynamic loading method and devices, are keeping project framework constant to realize In the case where can still realize dynamically load to module.
Referring to Fig. 1, a kind of method flow diagram of module dynamic loading method disclosed by the embodiments of the present invention, this method includes Step:
Step S101, when needing dynamically load application module, a new servlet service object is constructed;
Wherein, the application module for needing dynamically load can be MVC module.
The full name of Servlet is Java Servlet, is the server with written in Java.
Step S102, when receiving servlet request, servlet request is sent to original servlet service pair As;
It should be noted that due to new servlet service object and original servlet service object adhere to separately it is different ClassLoader (Classloader), new servlet service object are sightless for server, therefore for client The servlet of transmission is requested, and server can still send it to original servlet service object.
Step S103, servlet request is transmitted to using the original servlet service object described new Servlet service object is handled, to realize the dynamic to the application module by the new servlet service object Load;
Wherein, to make new servlet service object come into force, server need to be incited somebody to action by original servlet service object Servlet request is transmitted to new servlet service object, to realize application modules by new servlet service object Dynamically load.
Step S104, it after the completion of new servlet service object building, is constructed when destroying last module dynamically load Servlet service object.
It should be noted that original servlet service object is constructed by server (for example, Tomcat), own Original servlet service object can be all sent to by the request of server to handle, the present invention will be by that will be sent to original The servlet request of the servlet service object of beginning is transmitted to new servlet service object and handles, and realizing will Servlet request is forwarded to new servlet service object from original servlet service object, to realize application modules Dynamically load.Therefore, actually there are two servlet service objects in server in the present invention: an original servlet Service object and a new servlet service object, the address of new servlet service object are stored in original In servlet service object, original servlet service object exists always, will not be destroyed.In servlet new every time After the completion of service object creates, what new servlet service object will replace constructing when last module dynamically load Servlet service object, based on the considerations of server performance, it is also necessary to be constructed when destroying last module dynamically load Servlet service object.
Wherein, the present invention does not modify to original servlet service object but constructs new servlet service pair As the reason of are as follows: original servlet service object be by server (for example, Tomcat) construct, it is all to pass through server Request can all be sent to original servlet service object and handle.If desired the request that client is sent is handed to Other servlet service object must just modify the servlet build mechanism or request transmission mechanism of server, thus It can go deep into the details of server, dependence is generated to specific server, ultimately causes being highly coupled for project and server.Cause This, the present invention directly modifies the technological means of original servlet service object there is no using, but uses and construct newly Servlet request is transmitted to new servlet service pair by original servlet service object by servlet service object As realizing the dynamically load of application modules, wherein the application module can be new application module.
In summary, the present invention can construct a new servlet service pair in each dynamically load application module As servlet request being then transmitted to new servlet service object using original servlet service object, by new Servlet service object realize application modules dynamically load.For existing scheme, the present invention is without rebuilding Project framework only need to construct new servlet service object in each dynamically load application module, it is achieved that The dynamically load to module can be still realized in the case where keeping project framework constant, be not only easy to realize, and learning cost Low, the manpower of consuming and time are less.
In addition, compared to existing technologies, implementation of the present invention is simple and easy, does not need developer and dynamically load is answered Excessive concern is carried out with the details of module, developer is facilitated to use, and easy to maintain.
It should be noted that the present invention is that the SpringMVC frame based on lightweight is realized.
In order to further optimize the above embodiments, referring to fig. 2, the invention also discloses construct new servlet service object Detailed process, comprising steps of
Step S201, when needing dynamically load application module, obtaining application module needs all resources to be loaded;
Wherein, it includes: class file, jar packet, configuration file etc. that application module, which needs all resources to be loaded,.
Step S202, ClassLoader predetermined is constructed using all resources;
Wherein, Classloader (Chinese are as follows: Classloader) is that one kind is used to load java class to Java Virtual Machine One of loader.
Since new servlet service object and original servlet service object adhere to different ClassLoader separately, Therefore, a ClassLoader need to be pre-defined for new servlet service object.
Step S203, call spring Request dispatcher initial method, to the resource in the ClassLoader into Row building obtains new servlet service object;
Specifically, the initial method of spring Request dispatcher is called, to described using the reflection mechanism of java Resource in ClassLoader is constructed to obtain new servlet service object.
Step S204, the address of new servlet service object is saved into original servlet service object.
Wherein, the address of new servlet service object is saved to the purpose into original servlet service object It is: makes original servlet service object after receiving servlet request, new servlet can be found by the address Servlet request is forwarded to new servlet service object by service object.
Wherein, in the present embodiment, step S202 be can specifically include:
All resources to be loaded are needed to be divided into fixed class resource and variation class resource application module first;Secondly it utilizes URLClassLoader (Chinese: uniform resource locator loader) is constructed to obtain father to the fixed class resource to be added Carry device;Again using father's loader as parent, variation class resource is constructed to obtain sub- load using URLClassLoader Device, wherein father's loader and sub- loader constitute the ClassLoader in step S202.
It should be noted that require to reconfigure sub- loader when needing dynamically load application module every time, it is same with this When, father's loader can be always maintained at constant.
Wherein, in above-described embodiment, servlet is requested to forward by step S103 using original servlet service object It handles to new servlet service object, the application module is moved with being realized by new servlet service object The process of state load specifically includes:
Belong to same kind first, it is determined that whether there is in servlet request but adhere to asking for different ClassLoader separately It asks, if it exists the request, then the attribute in the first request entity corresponding to the request replicates, and obtains the first request entity Duplication attribute;Then (namely pre- in step S202 according to the resource in duplication attribute and ClassLoader predetermined The resource in ClassLoader first defined, the resource are also that application module needs all resources to be loaded), it obtains second and asks Realistic body;The second request entity is finally transmitted to the new servlet service pair using original servlet service object As being handled, to realize the dynamically load of application modules by new servlet service object.
It should be noted that the process of the network asynchronous request tool-class of the present embodiment namely modification extension spring.
In order to further optimize the above embodiments, the invention also discloses destroy original servlet service pair referring to Fig. 3 The detailed process of elephant, comprising steps of
Step S301, it after the completion of new servlet service object building, is constructed when destroying last module dynamically load Servlet service object in resource in network application container (WebApplicationContext), and the network is answered Sky is set to container;
Step S302, in the servlet service object's neutron loader constructed when destroying last module dynamically load Resource, and the sub- loader is set to sky;
Step S303, the servlet service object constructed when destroying last module dynamically load.
It is understood that constructed when destroying upper primary module dynamically load servlet service object during, Many system rubbish will necessarily be generated, system rubbish not only occupies Installed System Memory, also will affect the speed of service of system, therefore, After the servlet that the present invention is constructed when having destroyed upper primary module dynamically load, entire Destruction can also be generated Rubbish is purged.
Therefore, in order to further optimize the above embodiments, after step S303, can also include:
Step S304, using system rubbish recovering method to the servlet constructed when destroying last module dynamically load The rubbish generated during service object recycles.
Wherein, system rubbish recovering method can select System.gc ().
Corresponding with above method embodiment, the invention also discloses a kind of module dynamic loading devices.
Referring to fig. 4, the structural schematic diagram of a kind of module dynamic loading device disclosed by the embodiments of the present invention, the device packet It includes:
Construction unit 401, for constructing a new servlet service object when needing dynamically load application module;
It should be noted that due to new servlet service object and original servlet service object adhere to separately it is different ClassLoader (Classloader), new servlet service object are sightless for server, therefore for client The servlet of transmission is requested, and server can still send it to original servlet service object.
Transmission unit 402, for servlet request being sent to original when receiving servlet request Servlet service object;
Retransmission unit 403, for being transmitted to servlet request using the original servlet service object The new servlet service object is handled, and applies mould to described to realize by the new servlet service object The dynamically load of block;
Wherein, to make new servlet service object come into force, server need to be incited somebody to action by original servlet service object Servlet request is transmitted to new servlet service object, to realize application modules by new servlet service object Dynamically load.
Unit 404 is destroyed, after the completion of working as new servlet service object building, last module dynamic is destroyed and adds The servlet service object constructed when load.
It should be noted that original servlet service object is constructed by server (for example, Tomcat), own Original servlet service object can be all sent to by the request of server to handle, the present invention will be by that will be sent to original The servlet request of the servlet service object of beginning is transmitted to new servlet service object and handles, and realizing will Servlet request is forwarded to new servlet service object from original servlet service object, to realize application modules Dynamically load.Therefore, actually there are two servlet service objects in server in the present invention: an original servlet Service object and a new servlet service object, the address of new servlet service object are stored in original In servlet service object, original servlet service object exists always, will not be destroyed.In servlet new every time After the completion of service object creates, what new servlet service object will replace constructing when last module dynamically load Servlet service object, based on the considerations of server performance, it is also necessary to be constructed when destroying last module dynamically load Servlet service object.
In summary, the present invention can construct a new servlet service pair in each dynamically load application module As servlet request being then transmitted to new servlet service object using original servlet service object, by new Servlet service object realize application modules dynamically load.For existing scheme, the present invention is without rebuilding Project framework only need to construct new servlet service object in each dynamically load application module, it is achieved that The dynamically load to module can be still realized in the case where keeping project framework constant, be not only easy to realize, and learning cost Low, the manpower of consuming and time are less.
In addition, compared to existing technologies, implementation of the present invention is simple and easy, does not need developer and dynamically load is answered Excessive concern is carried out with the details of module, developer is facilitated to use, and easy to maintain.
It should be noted that the present invention is that the SpringMVC frame based on lightweight is realized.
In order to further optimize the above embodiments, referring to Fig. 5, a kind of structure of construction unit disclosed by the embodiments of the present invention is shown It is intended to, comprising:
Subelement 501 is obtained, it need to be to be loaded for when needing dynamically load application module, obtaining the application module All resources;
Wherein, it includes: class file, jar packet, configuration file etc. that application module, which needs all resources to be loaded,.
Subelement 502 is constructed, for constructing Classloader ClassLoader predetermined using all resources;
Subelement 503 is instantiated, for calling the initial method of spring Request dispatcher, to described Resource in ClassLoader is constructed to obtain the new servlet service object;
Saving subunit 504, for saving the address of the new servlet service object to described original In servlet service object.
Wherein, the address of new servlet service object is saved to the purpose into original servlet service object It is: makes original servlet service object after receiving servlet request, new servlet can be found by the address Servlet request is forwarded to new servlet service object by service object.
Wherein, in the present embodiment, construction subelement 502 be can specifically include:
Resource category divides subelement, for all resources to be divided into fixed class resource and variation class resource;
Father's loader constructs subelement, for utilizing uniform resource locator loader URLClassLoader to described solid Determine class resource to be constructed to obtain father's loader;
Sub- loader constructs subelement, for utilizing the URLClassLoader using father's loader as parent The variation class resource is constructed to obtain sub- loader, wherein described in father's loader and the sub- loader composition ClassLoader。
It should be noted that require to reconfigure sub- loader when needing dynamically load application module every time, it is same with this When, father's loader can be always maintained at constant.
Wherein, in order to further optimize the above embodiments, retransmission unit 403 can specifically include:
Judgment sub-unit, for judging in servlet request with the presence or absence of belonging to same kind but adhere to difference separately The request of ClassLoader;
Subelement is replicated, in the case where the judgment sub-unit is judged as YES, then corresponding to the request the Attribute in one request entity is replicated, and the duplication attribute of first request entity is obtained;
Second request entity obtains subelement, for according in the duplication attribute and ClassLoader predetermined Resource, the second request entity is obtained, wherein the resource is that the application module needs all resources to be loaded;
Subelement is forwarded, for being transmitted to second request entity using the original servlet service object The new servlet service object is handled, and applies mould to described to realize by the new servlet service object The dynamically load of block.
It should be noted that the process of the network asynchronous request tool-class of the present embodiment namely modification extension spring.
In order to further optimize the above embodiments, participate in Fig. 6, it is disclosed by the embodiments of the present invention it is a kind of destroy unit structure show It is intended to, destroying unit includes:
First destroys subelement 601, for destroying last module after the completion of new servlet service object building Resource in the servlet service object constructed when dynamically load in network application container (WebApplicationContext), And the network application container is set to sky;
Second destroys subelement 602, and servlet service object's neutron for constructing when last module dynamically load adds The resource in device is carried, and the sub- loader is set to sky;
Third destroys subelement 603, the servlet service object constructed when for destroying last module dynamically load.
It is understood that constructed when destroying upper primary module dynamically load servlet service object during, Many system rubbish will necessarily be generated, system rubbish not only occupies Installed System Memory, also will affect the speed of service of system, therefore, It, can also be to the rubbish of entire Destruction generation after the servlet that the present invention is constructed when having destroyed upper primary module dynamically load Rubbish is purged.
Therefore, in order to further optimize the above embodiments, can also include:
Garbage reclamation subelement 604 is constructed for destroying when subelement 603 destroys upper primary module dynamically load in third Servlet after, the servlet constructed when destroying last module dynamically load is serviced using system rubbish recovering method The rubbish generated during object is recycled.
Wherein, system rubbish recovering method can select System.gc ().
It should be noted that the concrete operating principle of each component part refers to embodiment of the method correspondence in Installation practice Part, details are not described herein again.
Finally, it is to be noted that, herein, relational terms such as first and second and the like be used merely to by One entity or operation are distinguished with another entity or operation, without necessarily requiring or implying these entities or operation Between there are any actual relationship or orders.Moreover, the terms "include", "comprise" or its any other variant meaning Covering non-exclusive inclusion, so that the process, method, article or equipment for including a series of elements not only includes that A little elements, but also including other elements that are not explicitly listed, or further include for this process, method, article or The intrinsic element of equipment.In the absence of more restrictions, the element limited by sentence "including a ...", is not arranged Except there is also other identical elements in the process, method, article or apparatus that includes the element.
Each embodiment in this specification is described in a progressive manner, the highlights of each of the examples are with other The difference of embodiment, the same or similar parts in each embodiment may refer to each other.
The foregoing description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, as defined herein General Principle can be realized in other embodiments without departing from the spirit or scope of the present invention.Therefore, of the invention It is not intended to be limited to the embodiments shown herein, and is to fit to and the principles and novel features disclosed herein phase one The widest scope of cause.

Claims (10)

1. a kind of module dynamic loading method characterized by comprising
When needing dynamically load application module, a new servlet service object is constructed;
When receiving servlet request, servlet request is sent to original servlet service object;
Servlet request is transmitted to the new servlet service pair using the original servlet service object As being handled, to realize the dynamically load to the application module by the new servlet service object, comprising: sentence The servlet that breaks whether there is the request for belonging to same kind but adhering to different ClassLoader separately in requesting;It is described if it exists Request then replicates the attribute in corresponding first request entity of the request, obtains answering for first request entity Attribute processed;According to the resource in the duplication attribute and ClassLoader predetermined, the second request entity is obtained, wherein The resource is that the application module needs all resources to be loaded;It will be described using the original servlet service object Second request entity is transmitted to the new servlet service object and handles, to pass through the new servlet service pair As realizing the dynamically load to the application module;
After the completion of the new servlet service object building, the servlet that is constructed when destroying last module dynamically load Service object.
2. module dynamic loading method according to claim 1, which is characterized in that described to need dynamically load application mould When block, one new servlet service object of building includes:
When needing dynamically load application module, obtaining the application module needs all resources to be loaded;
Classloader ClassLoader predetermined is constructed using all resources;
The initial method for calling spring Request dispatcher, constructs the resource in the ClassLoader to obtain institute State new servlet service object;
The address of the new servlet service object is saved into the original servlet service object.
3. module dynamic loading method according to claim 2, which is characterized in that described to be constructed using all resources Classloader ClassLoader predetermined includes:
All resources are divided into fixed class resource and variation class resource;
The fixed class resource is constructed using uniform resource locator loader URLClassLoader to obtain father's load Device;
Using father's loader as parent, the variation class resource is constructed to obtain using the URLClassLoader Sub- loader, wherein father's loader and the sub- loader constitute the ClassLoader.
4. module dynamic loading method according to claim 1, which is characterized in that described when the new servlet clothes It is engaged in after the completion of object building, the process of the servlet service object constructed when destroying last module dynamically load includes:
After the completion of the new servlet service object building, constructed when destroying the last module dynamically load Resource in servlet service object in network application container, and the network application container is set to sky;
The resource in servlet service object's neutron loader constructed when destroying the last module dynamically load, and will The sub- loader is set to sky;
The servlet service object constructed when destroying the last module dynamically load.
5. module dynamic loading method according to claim 4, which is characterized in that destroying the upper primary module dynamic After the servlet service object constructed when load, further includes:
Using system rubbish recovering method to the servlet service object's constructed when destroying the last module dynamically load The rubbish generated in the process is recycled.
6. a kind of module dynamic loading device characterized by comprising
Construction unit, for constructing a new servlet service object when needing dynamically load application module;
Transmission unit, for servlet request being sent to original servlet and is taken when receiving servlet request Business object;
Retransmission unit is described new for being transmitted to servlet request using the original servlet service object Servlet service object is handled, to realize the dynamic to the application module by the new servlet service object Load;
Unit is destroyed, after the completion of working as the new servlet service object building, when destroying last module dynamically load The servlet service object of building;
Wherein, the retransmission unit includes:
Judgment sub-unit, for judging in servlet request with the presence or absence of belonging to same kind but adhere to difference separately The request of ClassLoader;
Subelement is replicated, in the case where the judgment sub-unit is judged as YES, then asking to the request corresponding first Attribute in realistic body is replicated, and the duplication attribute of first request entity is obtained;
Second request entity obtains subelement, for according to the money in the duplication attribute and ClassLoader predetermined Source obtains the second request entity, wherein the resource is that the application module needs all resources to be loaded;
Subelement is forwarded, it is described for being transmitted to second request entity using the original servlet service object New servlet service object is handled, to be realized by the new servlet service object to the application module Dynamically load.
7. module dynamic loading device according to claim 6, which is characterized in that the construction unit includes:
Subelement is obtained, needs all moneys to be loaded for when needing dynamically load application module, obtaining the application module Source;
Subelement is constructed, for constructing Classloader ClassLoader predetermined using all resources;
Subelement is instantiated, for calling the initial method of spring Request dispatcher, to the money in the ClassLoader Source is constructed to obtain the new servlet service object;
Saving subunit is serviced for saving the address of the new servlet service object to the original servlet In object.
8. module dynamic loading device according to claim 7, which is characterized in that the construction subelement includes:
Resource category divides subelement, for all resources to be divided into fixed class resource and variation class resource;
Father's loader constructs subelement, for utilizing uniform resource locator loader URLClassLoader to the fixed class Resource is constructed to obtain father's loader;
Sub- loader constructs subelement, is used for using father's loader as parent, using the URLClassLoader to institute It states variation class resource to be constructed to obtain sub- loader, wherein described in father's loader and the sub- loader composition ClassLoader。
9. module dynamic loading device according to claim 6, which is characterized in that the destruction unit includes:
First destroys subelement, for destroying the last module after the completion of the new servlet service object building Resource in the servlet service object constructed when dynamically load in network application container, and the network application container is set For sky;
Second destroys subelement, the servlet service object's neutron constructed when for destroying the last module dynamically load Resource in loader, and the sub- loader is set to sky;
Third destroys subelement, the servlet service object constructed when for destroying the last module dynamically load.
10. module dynamic loading device according to claim 6, which is characterized in that further include:
Garbage reclamation subelement, servlet service object for being constructed when destroying the upper primary module dynamically load it Afterwards, using system rubbish recovering method to the servlet service object's constructed when destroying the last module dynamically load The rubbish generated in the process is recycled.
CN201610757151.0A 2016-08-29 2016-08-29 A kind of module dynamic loading method and device Active CN106354533B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610757151.0A CN106354533B (en) 2016-08-29 2016-08-29 A kind of module dynamic loading method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610757151.0A CN106354533B (en) 2016-08-29 2016-08-29 A kind of module dynamic loading method and device

Publications (2)

Publication Number Publication Date
CN106354533A CN106354533A (en) 2017-01-25
CN106354533B true CN106354533B (en) 2019-09-20

Family

ID=57857646

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610757151.0A Active CN106354533B (en) 2016-08-29 2016-08-29 A kind of module dynamic loading method and device

Country Status (1)

Country Link
CN (1) CN106354533B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109033436A (en) * 2018-08-14 2018-12-18 武汉达梦数据库有限公司 A kind of multiple version JDBC driving coexistence methods of same database and system

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7069553B2 (en) * 2003-03-03 2006-06-27 Computer Associates Think, Inc. Universal deployment tool
CN104360846A (en) * 2014-10-27 2015-02-18 江西博微新技术有限公司 OSGi-based adaptive design method for authority management of Web application development platform based on OSGi
CN105512324B (en) * 2015-12-21 2019-01-15 用友网络科技股份有限公司 A kind of front-end module loader of packaging file local updating

Also Published As

Publication number Publication date
CN106354533A (en) 2017-01-25

Similar Documents

Publication Publication Date Title
CN101188566B (en) A method and system for data buffering and synchronization under cluster environment
CN104935672B (en) Load balancing service high availability implementation method and equipment
CN103064742A (en) Automatic deployment system and method of hadoop cluster
CN106406905B (en) Configuration method and system for SETUP option of BIOS of server
CN113742031B (en) Node state information acquisition method and device, electronic equipment and readable storage medium
CN102916995A (en) Application hosting method and system
JP7438355B2 (en) Node management method, device, equipment, storage medium and system
CN105429839A (en) Virtualized network function VNF optimization method, device and system
US20160352843A1 (en) Data Processing Method, Device, and ESB System
CN105516086A (en) Service processing method and apparatus
CN103873534A (en) Method and device for application cluster migration
CN105959302A (en) Terminal management framework and method
CN114691567A (en) Multi-cloud interface adaptation method, system and storage medium based on micro-service
CN102479355A (en) Method and device for loading business documents and mobile terminal
CN106354533B (en) A kind of module dynamic loading method and device
CN102831494A (en) Scheduling method, scheduling device and scheduling system
CN115248692A (en) Device and method for supporting cloud deployment of multiple deep learning framework models
CN102316163A (en) Method for realizing Web container expansion and Web container
CN101459740B (en) Method for deploying SIP Servlet application, managing SIP Servlet application and system thereof
CN101753360B (en) Method applying system start-up, parallel management system and application management system
CN116243930A (en) Multi-version parallel environment design method and construction system
CN105827567B (en) Service management and control method and capability opening platform
CN101888379A (en) Multi-proxy server dynamic linking method of network television and network television system
CN104063451A (en) Database connection management method and system
CN109308222B (en) Decentralized software and hardware resource cloud platform building method based on unified modeling environment

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant