CN106933611A - Kind loading method and Classloader - Google Patents

Kind loading method and Classloader Download PDF

Info

Publication number
CN106933611A
CN106933611A CN201511023447.1A CN201511023447A CN106933611A CN 106933611 A CN106933611 A CN 106933611A CN 201511023447 A CN201511023447 A CN 201511023447A CN 106933611 A CN106933611 A CN 106933611A
Authority
CN
China
Prior art keywords
classloader
lib
plug
unit
class
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.)
Granted
Application number
CN201511023447.1A
Other languages
Chinese (zh)
Other versions
CN106933611B (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 58 Information Technology Co Ltd
Original Assignee
Beijing 58 Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing 58 Information Technology Co Ltd filed Critical Beijing 58 Information Technology Co Ltd
Priority to CN201511023447.1A priority Critical patent/CN106933611B/en
Publication of CN106933611A publication Critical patent/CN106933611A/en
Application granted granted Critical
Publication of CN106933611B publication Critical patent/CN106933611B/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
    • G06F9/44526Plug-ins; Add-ons

Abstract

The present invention provides a kind of kind loading method and Classloader;A kind of kind loading method includes:First Classloader searches the first kind in the storehouse LIB of plug-in unit;Wherein, the plug-in unit includes first Classloader;If first Classloader finds the first kind in the LIB, using the definition of the first kind described in the LIB, the first kind is loaded.The present invention can not include identical class in solving the LIB of the plug-in unit in the prior art and LIB of host program, and cause the problem of application development inconvenience.

Description

Kind loading method and Classloader
Technical field
The present invention relates to computer realm, more particularly to a kind of kind loading method and Classloader.
Background technology
Host program is for the carrier for plug-in component operation, while also specify the access criteria of plug-in unit.Insert Part is a kind of program module, that is, refer to the access criteria for meeting service platform, can run on service platform , and non-serving platform necessary function or business module in itself.Wherein, plug-in unit and host's journey Sequence can be packaged in different Android installation kits (APK, Android Package).
In the prior art, each APK can include a storehouse (LIB, Library), in LIB Definition including class.When the Classloader of plug-in unit needs one class of loading:The Classloader first can Notify that father's loader of the Classloader loads such;When father's loader is in the LIB of host program When finding such, such the definition in the LIB of host program completes such loading, and Such object is returned into the Classloader;When father's loader is not looked into the LIB of host program When finding such, such lookup result will not found and return to the Classloader, by the Classloader Complete such loading;When the Classloader receives such object of father's loader return, and should When Classloader determines to also include such definition in the LIB of plug-in unit, it may appear that class repeats loading Mistake.
Therefore, exist in the prior art can not include in the LIB of the plug-in unit and LIB of host program it is identical Class, and cause application development inconvenience problem.
The content of the invention
The present invention provides a kind of kind loading method and Classloader, is used to solve plug-in unit in the prior art Identical class can not be included in the LIB of LIB and host program, and cause asking for application development inconvenience Topic.
The present invention provides a kind of kind loading method, including:
First Classloader searches the first kind in the LIB of plug-in unit;Wherein, the plug-in unit includes described the One Classloader;
If first Classloader finds the first kind in the LIB, the LIB is used Described in the first kind definition, the first kind is loaded.
Optionally, in an embodiment of the present invention, first Classloader is searched in the LIB of plug-in unit After the first kind, also include:
If first Classloader does not find the first kind in the LIB, Equations of The Second Kind is notified Loader is loaded to the first kind;
Wherein, second Classloader is father's loader of first Classloader.
Optionally, in an embodiment of the present invention, first Classloader is searched in the LIB of plug-in unit Before the first kind, or first Classloader is also wrapped after the lookup first kind in the LIB of plug-in unit Include:
First Classloader by all classes defined in the LIB, in second Classloader Registered.
Optionally, in an embodiment of the present invention, first Classloader is by defined in the LIB All classes, are registered in second Classloader, including:
First Classloader is by the path of the class name of all classes defined in the LIB and the plug-in unit Corresponding relation, be added to the class list of second Classloader.
Optionally, in an embodiment of the present invention, first Classloader is DexClassLoader, Second Classloader is PathClassLoader.
The present invention provides a kind of Classloader, and the Classloader is the first Classloader, the class loading Device includes:
Searching modul, for searching the first kind in the LIB of plug-in unit;Wherein, the plug-in unit includes described Classloader;
Load-on module, if finding the first kind in the LIB for the searching modul, makes With the definition of the first kind described in the LIB, the first kind is loaded.
Optionally, in an embodiment of the present invention, also include:Notification module, if for the lookup mould Block does not find the first kind in the LIB, then notify that the second Classloader enters to the first kind Row loading;
Wherein, second Classloader is father's loader of first Classloader.
Optionally, in an embodiment of the present invention, also include:Registering modules, for by the LIB All classes of definition, are registered in second Classloader.
Optionally, in an embodiment of the present invention, the Registering modules, specifically for by the LIB The class name of all classes of definition and the corresponding relation in the path of the plug-in unit, are added to the Equations of The Second Kind loading The class list of device.
Optionally, in an embodiment of the present invention, first Classloader is DexClassLoader, Second Classloader is PathClassLoader.
The present invention provides a kind of kind loading method and Classloader;Loading is needed by when the first Classloader During the first kind, the first kind is searched in the LIB of plug-in unit;If finding the first kind in the LIB, Then using the definition of the first kind described in the LIB, the first kind is loaded;So that working as plug-in unit LIB and host program LIB in when all including the first kind, be not in that the Classloader of plug-in unit is received Such object that father's loader of the Classloader is returned, and the Classloader of plug-in unit determines plug-in unit The scene of such definition is also included in LIB;Therefore, be also not in the mistake of class repetition loading; So that can include identical class in the LIB of the LIB of plug-in unit and host program, the exploitation of application program is more Plus flexibly, conveniently.
Brief description of the drawings
In order to illustrate more clearly about the embodiment of the present invention or technical scheme of the prior art, below will be to reality The accompanying drawing to be used needed for example or description of the prior art is applied to be briefly described, it should be apparent that, under Accompanying drawing in the description of face is some embodiments of the present invention, for those of ordinary skill in the art, On the premise of not paying creative labor, other accompanying drawings can also be obtained according to these accompanying drawings.
Fig. 1 is the flow chart of kind loading method embodiment one of the present invention;
Fig. 2 is the flow chart of kind loading method embodiment two of the present invention;
Fig. 3 is the flow chart of kind loading method embodiment three of the present invention;
Fig. 4 is the structural representation of Classloader embodiment one of the present invention;
Fig. 5 is the structural representation of Classloader embodiment two of the present invention.
Specific embodiment
To make the purpose, technical scheme and advantage of the embodiment of the present invention clearer, below in conjunction with this hair Accompanying drawing in bright embodiment, is clearly and completely described to the technical scheme in the embodiment of the present invention, Obviously, described embodiment is a part of embodiment of the invention, rather than whole embodiments.It is based on Embodiment in the present invention, those of ordinary skill in the art are obtained under the premise of creative work is not made The every other embodiment for obtaining, belongs to the scope of protection of the invention.
Fig. 1 is the flow chart of kind loading method embodiment one of the present invention;As shown in figure 1, the present embodiment Method can include:
Step 101, the first Classloader search the first kind in the LIB of plug-in unit;Wherein, the plug-in unit Including first Classloader;
If step 102, first Classloader find the first kind in the LIB, make With the definition of the first kind described in the LIB, the first kind is loaded.
In the present embodiment, by when the first Classloader needs the loading first kind, in the LIB of plug-in unit Search the first kind;If finding the first kind in the LIB, using first described in the LIB The definition of class, loads to the first kind;So that when in the LIB of plug-in unit and the LIB of host program All include the first kind when, be not in plug-in unit Classloader receive the Classloader father's loader return Such object, and the Classloader of plug-in unit determines to also include such definition in the LIB of plug-in unit Scene;Therefore, be also not in the mistake of class repetition loading;So that the LIB of plug-in unit and host program Identical class can be included in LIB, the exploitation of application program more facilitates;Solve and insert in the prior art Identical class can not be included in the LIB of the part and LIB of host program, and cause application development inconvenience Problem.
Fig. 2 is the flow chart of kind loading method embodiment two of the present invention;As shown in Fig. 2 the present embodiment Method can include:
Step 201, the first Classloader search the first kind in the LIB of plug-in unit;Wherein, the plug-in unit Including first Classloader;
Optionally, first Classloader is that Android (android) system extends Classloader DexClassLoader。
If step 202, first Classloader find the first kind in the LIB, make With the definition of the first kind described in the LIB, the first kind is loaded;
If step 203, first Classloader do not find the first kind in the LIB, Notify that the second Classloader is loaded to the first kind.
Wherein, second Classloader is father's loader of first Classloader.
Optionally, second Classloader is that Android android operating systems give tacit consent to Classloader PathClassLoader。
Optionally, second Classloader is loaded to the first kind, including:The Equations of The Second Kind Loader searches the first kind in the LIB of host program, and after the first kind is found, uses The definition of the first kind described in the LIB of the host program, loads to the first kind.
Optionally, before step 201 or after step 201, can also include:The first kind loading Device is registered all classes defined in the LIB in second Classloader.Due to when the When tripartite jar bags are with reflex mechanism loading classes, the second Classloader is used to be loaded, and existing skill The second Classloader can not load the class defined in the LIB of plug-in unit in art;In the present embodiment, by inciting somebody to action All classes defined in the lIB, are registered so that third party Jar in second Classloader Bag can load the class defined in the LIB of the plug-in unit by the second Classloader.
It should be noted that all classes by defined in the LIB, in second loader The operation registered, can be realized by first Classloader, or can also be by the plug-in unit Other codes realize.
Optionally, first Classloader is by all classes defined in the LIB, in the Equations of The Second Kind Registered in loader, including:
First Classloader is by the path of the class name of all classes defined in the LIB and the plug-in unit Corresponding relation, be added to the class list of second Classloader.
Wherein, the class list can be with as shown in table 1 below;
Table 1
Class name Path
aa 11\22\33
bb 11\22\33
…… ……
Wherein, aa, bb are the class name of the class defined in the LIB of the plug-in unit, 11 22 33 inserted for described The path of part.
In the present embodiment, by when the first Classloader needs the loading first kind, in the LIB of plug-in unit Search the first kind;If finding the first kind in the LIB, using first described in the LIB The definition of class, loads to the first kind;If first Classloader is not looked into the LIB The first kind is found, then notifies that the second Classloader is loaded to the first kind;So that working as plug-in unit LIB and host program LIB in when all including the first kind, be not in that the Classloader of plug-in unit is received Such object that father's loader of the Classloader is returned, and the Classloader of plug-in unit determines plug-in unit The scene of such definition is also included in LIB;Therefore, be also not in the mistake of class repetition loading; So that can include identical class in the LIB of the LIB of plug-in unit and host program, the exploitation of application program is more Plus it is convenient, improve development efficiency.
Fig. 3 is the flow chart of kind loading method embodiment three of the present invention;As shown in figure 3, in step 301, DexClassLoader first looks for the definition of a certain class from the LIB A of plug-in unit itself;In step 302 when When DexClassLoader does not find such definition in the LIB A of plug-in unit, then father's loader is notified PathClassLoader looks for such definition from the LIB B of host program.
In the present embodiment, by rewriteeing the pattern of DexClassLoader loading classes, remove parents and appoint original Use then, allows plug-in unit preferentially to use the class defined in the LIB of plug-in unit;So as to allow the LIB of plug-in unit Include identical class with the LIB of host.
Fig. 4 is the structural representation of Classloader embodiment one of the present invention, the Classloader in the present embodiment It is the first Classloader;As shown in figure 4, the Classloader of the present embodiment can include:Searching modul 401 With load-on module 402.Wherein, searching modul 401, for searching the first kind in the storehouse LIB of plug-in unit; Wherein, the plug-in unit includes the Classloader;Load-on module 402, if existing for the searching modul The first kind is found in the LIB, then using the definition of the first kind described in the LIB, to institute The first kind is stated to be loaded.
The Classloader of the present embodiment, can be used for performing the technical scheme of embodiment of the method shown in Fig. 1, Its realization principle is similar with technique effect, and here is omitted.
Fig. 5 is the structural representation of Classloader embodiment two of the present invention, as shown in figure 5, the present embodiment Classloader on the basis of Classloader structure shown in Fig. 4, further, can also include:It is logical Know module 403, if not finding the first kind in the LIB for the searching modul, lead to Know that the second Classloader is loaded to the first kind.
Optionally, the Classloader of the present embodiment, can also include:Registering modules 404, for by institute The all classes defined in LIB are stated, is registered in second Classloader.
Optionally, Registering modules 404, specifically for by the class name of all classes defined in the LIB with The corresponding relation in the path of the plug-in unit, is added to the class list of second Classloader.
Optionally, first Classloader is DexClassLoader, and second Classloader is PathClassLoader。
The Classloader of the present embodiment, can be used for performing the technology of embodiment of the method shown in Fig. 2, Fig. 3 Scheme, its realization principle is similar with technique effect, and here is omitted.
One of ordinary skill in the art will appreciate that:Realize all or part of step of above-mentioned each method embodiment Suddenly can be completed by the related hardware of programmed instruction.Foregoing program can be stored in a computer can In reading storage medium.The program upon execution, performs the step of including above-mentioned each method embodiment;And Foregoing storage medium includes:ROM, RAM, magnetic disc or CD etc. are various can be with store program codes Medium.
Finally it should be noted that:Various embodiments above is merely illustrative of the technical solution of the present invention, rather than right Its limitation;Although being described in detail to the present invention with reference to foregoing embodiments, this area it is common Technical staff should be understood:It can still modify to the technical scheme described in foregoing embodiments, Or equivalent is carried out to which part or all technical characteristic;And these modifications or replacement, and The scope of the essence disengaging various embodiments of the present invention technical scheme of appropriate technical solution is not made.

Claims (10)

1. a kind of kind loading method, it is characterised in that including:
First Classloader searches the first kind in the storehouse LIB of plug-in unit;Wherein, the plug-in unit includes described First Classloader;
If first Classloader finds the first kind in the LIB, the LIB is used Described in the first kind definition, the first kind is loaded.
2. method according to claim 1, it is characterised in that first Classloader is in plug-in unit LIB in search the first kind after, also include:
If first Classloader does not find the first kind in the LIB, Equations of The Second Kind is notified Loader is loaded to the first kind;
Wherein, second Classloader is father's loader of first Classloader.
3. method according to claim 2, it is characterised in that first Classloader is in plug-in unit LIB in search the first kind before, or first Classloader searches first in the LIB of plug-in unit After class, also include:
First Classloader by all classes defined in the LIB, in second Classloader Registered.
4. method according to claim 3, it is characterised in that first Classloader will be described All classes defined in LIB, are registered in second Classloader, including:
First Classloader is by the path of the class name of all classes defined in the LIB and the plug-in unit Corresponding relation, be added to the class list of second Classloader.
5. the method according to claim any one of 2-4, it is characterised in that the first kind loading Device is DexClassLoader, and second Classloader is PathClassLoader.
6. a kind of Classloader, the Classloader is the first Classloader, it is characterised in that the class Loader includes:
Searching modul, for searching the first kind in the storehouse LIB of plug-in unit;Wherein, the plug-in unit includes institute State Classloader;
Load-on module, if finding the first kind in the LIB for the searching modul, makes With the definition of the first kind described in the LIB, the first kind is loaded.
7. Classloader according to claim 6, it is characterised in that also include:Notification module, If not finding the first kind in the LIB for the searching modul, Equations of The Second Kind loading is notified Device is loaded to the first kind;
Wherein, second Classloader is father's loader of first Classloader.
8. Classloader according to claim 7, it is characterised in that also include:Registering modules, For by all classes defined in the LIB, being registered in second Classloader.
9. Classloader according to claim 8, it is characterised in that the Registering modules, specifically For by the class name of all classes defined in the LIB and the corresponding relation in the path of the plug-in unit, adding To the class list of second Classloader.
10. the Classloader according to claim any one of 7-9, it is characterised in that described first Classloader is DexClassLoader, and second Classloader is PathClassLoader.
CN201511023447.1A 2015-12-31 2015-12-31 Class loading method and class loader Active CN106933611B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201511023447.1A CN106933611B (en) 2015-12-31 2015-12-31 Class loading method and class loader

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201511023447.1A CN106933611B (en) 2015-12-31 2015-12-31 Class loading method and class loader

Publications (2)

Publication Number Publication Date
CN106933611A true CN106933611A (en) 2017-07-07
CN106933611B CN106933611B (en) 2020-04-28

Family

ID=59441725

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201511023447.1A Active CN106933611B (en) 2015-12-31 2015-12-31 Class loading method and class loader

Country Status (1)

Country Link
CN (1) CN106933611B (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106201592A (en) * 2016-06-29 2016-12-07 北京小米移动软件有限公司 A kind of method and apparatus searching class
CN109697103A (en) * 2018-08-21 2019-04-30 平安普惠企业管理有限公司 Kind loading method, device, equipment and readable storage medium storing program for executing
CN110308945A (en) * 2019-05-22 2019-10-08 百度在线网络技术(北京)有限公司 The dynamic loading method and device of plug-in unit
CN112131000A (en) * 2020-09-23 2020-12-25 腾讯科技(深圳)有限公司 Memory release method and device for plug-in application program
CN112612530A (en) * 2019-09-18 2021-04-06 华为技术有限公司 Class query method and device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070198484A1 (en) * 2006-02-22 2007-08-23 Nawaaz Ahmed Query serving infrastructure
CN102411506A (en) * 2011-07-07 2012-04-11 杭州典能科技有限公司 Java-system business-unit plug-in type managing system and dynamic business-function changing method
CN104699547A (en) * 2015-03-19 2015-06-10 北京东方通科技股份有限公司 Java EE application class loading conflict analyzing method and device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070198484A1 (en) * 2006-02-22 2007-08-23 Nawaaz Ahmed Query serving infrastructure
CN102411506A (en) * 2011-07-07 2012-04-11 杭州典能科技有限公司 Java-system business-unit plug-in type managing system and dynamic business-function changing method
CN104699547A (en) * 2015-03-19 2015-06-10 北京东方通科技股份有限公司 Java EE application class loading conflict analyzing method and device

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106201592A (en) * 2016-06-29 2016-12-07 北京小米移动软件有限公司 A kind of method and apparatus searching class
CN109697103A (en) * 2018-08-21 2019-04-30 平安普惠企业管理有限公司 Kind loading method, device, equipment and readable storage medium storing program for executing
CN110308945A (en) * 2019-05-22 2019-10-08 百度在线网络技术(北京)有限公司 The dynamic loading method and device of plug-in unit
CN110308945B (en) * 2019-05-22 2022-07-05 百度在线网络技术(北京)有限公司 Dynamic loading method and device of plug-in
CN112612530A (en) * 2019-09-18 2021-04-06 华为技术有限公司 Class query method and device
CN112612530B (en) * 2019-09-18 2022-05-17 华为技术有限公司 Class query method and device
CN112131000A (en) * 2020-09-23 2020-12-25 腾讯科技(深圳)有限公司 Memory release method and device for plug-in application program
CN112131000B (en) * 2020-09-23 2024-02-06 腾讯科技(深圳)有限公司 Memory release method and device for plug-in application program

Also Published As

Publication number Publication date
CN106933611B (en) 2020-04-28

Similar Documents

Publication Publication Date Title
CN106933611A (en) Kind loading method and Classloader
CN106970873B (en) On-line mock testing method, device and system
CN102932415B (en) Method and device for storing mirror image document
CN107741937A (en) A kind of data query method and device
CN103365668B (en) A kind of dynamic link library loads and the method, apparatus of link
CN111813805A (en) Data processing method and device
CN108614702B (en) Byte code optimization method and device
CN107247722B (en) File scanning method and device and intelligent terminal
CN105701190A (en) Data synchronizing method and device
CN110727581B (en) Crash positioning method and electronic equipment
CN109391512A (en) A kind of service issuing method, device and electronic equipment
CN102937993B (en) A kind of method for access key and device
CN109829678B (en) Rollback processing method and device and electronic equipment
CN104601645A (en) Data packet processing method and device
CN109388644B (en) Data updating method and device
US10528257B2 (en) Method and apparatus for reproducing an I/O operation of a storage system
CN111045783B (en) Method and device for generating container mirror image, storage medium and electronic equipment
CN112148709A (en) Data migration method, system and storage medium
CN111309432B (en) Fault drilling method, device and system
US9626371B2 (en) Attribute selectable file operation
CN103809947A (en) Automatic release method and system for development requirement
CN103176843B (en) The file migration method and apparatus of MapReduce distributed system
CN112860412B (en) Service data processing method and device, electronic equipment and storage medium
CN105975567B (en) Method and device for processing internal file of application program
CN112463596A (en) Test case data processing method, device and equipment and processing equipment

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
GR01 Patent grant
GR01 Patent grant