Class loading method, computer device, and storage device
By receiving the loading request of the class to be loaded and determining the preset loading mode based on its defining information, the problem of class conflicts during class loading is solved, and the optimization of class loading strategy and the improvement of application stability is achieved.
Patent Information
- Application Number
- CN202210268060.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-17
- Publication Date
- 2025-06-27
- Estimated Expiration
- 2042-03-17
AI Technical Summary
During class loading, the introduction of external classes may cause class conflict problems and affect the operation of the application. It is difficult for the existing technology to effectively resolve conflict-like problems.
By receiving the load request of the class to be loaded, the preset loading mode is determined based on its defining information, including at least one of loading from the application data packet, calling the connector class loader, and calling the parent class loader to optimize the class loading process.
It effectively reduces class conflict problems during class loading, optimizes class loading strategies, and improves the stability and efficiency of the application.
Smart Images

Figure CN114816561B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technologies, and particularly to a class loading method, a computer device, and a storage device. Background Art
[0002] With the development of open-source technologies and the increasing complexity and modularity of systems, functions developed by developers to continuously meet new requirements may require frequent addition of external classes. During the process of loading external classes, class conflict problems may occur, thus affecting the operation of the application program.
[0003] Currently, when a class conflict problem occurs during loading, it usually needs to be analyzed and solved by developers based on experience, which will have a certain impact on the running of the application program. After a class conflict problem occurs during loading, other methods for handling class conflict problems cannot well solve the class conflict problem either. Summary of the Invention
[0004] The main technical problem to be solved by this application is to provide a class loading method, a computer device, and a storage device, which can reduce class conflict problems during class loading.
[0005] To solve the above problems, in a first aspect of this application, a class loading method is provided. The method includes: receiving a loading request for a class to be loaded; determining a preset loading mode of the class to be loaded based on the naming information of the class to be loaded; where the preset loading mode includes at least one of loading from an application data packet, calling a connector class loader to load, and calling a parent class loader to load; and using the preset loading mode of the class to be loaded to perform a loading process on the class to be loaded.
[0006] To solve the above problems, in a second aspect of this application, a computer device is provided. The computer device includes a memory and a processor that are coupled to each other. Program data is stored in the memory, and the processor is configured to execute the program data to implement any step of the above class loading method.
[0007] To solve the above problems, in a third aspect of this application, a storage device is provided. The storage device stores program data that can be run by a processor, and the program data is used to implement any step of the above class loading method.
[0008] In the above solution, by receiving a loading request for a class to be loaded, since the preset loading mode is determined based on the naming information of the class to be loaded, and the preset loading mode includes loading from an application data packet, calling a connector class loader to load, and calling a parent class loader to load, it is possible to use the determined preset loading mode of the class to be loaded to perform a loading process on the class to be loaded, and class conflict problems during class loading can be reduced. Description of the Drawings
[0009] To more clearly illustrate the technical solutions in this application, the following will briefly introduce the accompanying drawings required in the description of the embodiments. Obviously, the accompanying drawings described below are only some embodiments of this application. For those of ordinary skill in the art, without creative efforts, other accompanying drawings can be obtained based on these drawings. Among them:
[0010] Figure 1 is a schematic flowchart of the first embodiment of the loading method of this application type;
[0011] Figure 2 is this application Figure 1 a schematic flowchart of one embodiment of step S12 in;
[0012] Figure 3 is a schematic flowchart of the second embodiment of the loading method of this application type;
[0013] Figure 4 is a schematic flowchart of the third embodiment of the loading method of this application type;
[0014] Figure 5 is a schematic structural diagram of one embodiment of the loading device of this application type;
[0015] Figure 6 is a schematic structural diagram of one embodiment of the computer device of this application;
[0016] Figure 7 is a schematic structural diagram of one embodiment of the storage device of this application. Specific Embodiments
[0017] The following will clearly and completely describe the technical solutions in the embodiments of this application in conjunction with the accompanying drawings in the embodiments of this application. Obviously, the described embodiments are only some of the embodiments of this application, rather than all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope protected by this application.
[0018] The terms "first" and "second" in this application are only used for descriptive purposes and should not be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, features defined with "first" and "second" may explicitly or implicitly include at least one such feature. In the description of this application, the meaning of "a plurality" is at least two, such as two, three, etc., unless otherwise specifically defined. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally further include unlisted steps or units, or may optionally further include other steps or units inherent to these processes, methods, products, or devices.
[0019] Referring to "embodiments" in this application means that specific features, structures, or characteristics described in connection with the embodiments may be included in at least one embodiment of this application. The occurrence of this phrase at various positions in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein may be combined with other embodiments.
[0020] This application provides the following embodiments, and specific descriptions of each embodiment are given below.
[0021] Please refer to Figure 1 , Figure 1 which is a schematic flowchart of the first embodiment of the loading method of this application category. The method may include the following steps:
[0022] S11: Receive a loading request for the class to be loaded.
[0023] Flink is a distributed open-source computing framework for stream data and batch data, designed to run in all common cluster environments to perform computations at in-memory speeds and at any scale. Flink applications (Java applications) can run in Flink. Users can upload custom Jar packages, which contain one or more application codes and the required connectors and library dependencies. External Jar packages can be introduced for dependencies in Flink, and the same classes often exist in different Jar packages, which may lead to conflicting classes being introduced in the programs of the same information system.
[0024] The Flink connector is a component provided by Flink to connect the Flink computing engine with external storage systems for interaction. Connectors usually introduce heavy dependencies, and there may be problems of class conflicts between the codes of different connectors or jobs and the dependencies in the Flink lib directory.
[0025] When a class is loaded, for example, under the framework of the Java Virtual Machine (JVM), the JVM loads the bytecode.class file that describes the class data in the disk into the memory, and corrects, transforms, parses, and initializes this data, finally forming a Java type that can be directly used by the JVM.
[0026] A class is an abstract data type, which is an abstraction of entities with the same characteristics. The classes described in the embodiments of the present application usually refer to Java classes. A Java class is a basic component of a Java application, which describes the behaviors and states of a class of objects. A class usually includes constructors, member variables, and multiple methods. In some embodiments, a class can be considered as a collection of multiple attributes and methods.
[0027] In some embodiments, the class information of a class can include the class name, class definition, attributes of the class, methods, etc.
[0028] In some embodiments, the class information of a class can include all the information required to execute this class. For example, it includes all the class information of this class, such as the class name, class definition, attributes of the class, methods, and the external visibility of the attributes and methods.
[0029] When the JVM requests to load a class, the class to be loaded can be used as the class to be loaded. After receiving the loading request for the class to be loaded, it loads the class to be loaded.
[0030] S12: Based on the naming information of the class to be loaded, determine the preset loading mode of the class to be loaded; wherein, the preset loading mode includes at least one of loading from the application data packet, calling the connector class loader to load, and calling the parent class loader to load.
[0031] In some embodiments, the naming information of the class to be loaded can be the class name of the class to be loaded, and this class name can be the full name of the class name of the class to be loaded.
[0032] In some embodiments, the naming information of the class to be loaded can be class information, for example, it includes all the class information of this class, such as the class name, class definition, attributes of the class, methods, and the external visibility of the attributes and methods.
[0033] In some embodiments, the naming information of the class to be loaded can be the fully qualified name of the class, wherein the fully qualified name can include the class name and type of this class. For example, java.lang.String can express the reference from the most primitive and top - level place to the specific object.
[0034] In some embodiments, the naming information of the class to be loaded may represent information such as the class name of the class to be loaded, the class name of the corresponding parent class of the class to be loaded, and the class names of all upper-level parent classes of the parent class, so as to be able to express the reference method of the class to be loaded.
[0035] In the embodiments of the present application, the naming information of the class to be loaded described is taken as an example of the fully qualified name of the class, but the present application is not limited thereto.
[0036] Based on the naming information of the class to be loaded, the preset loading mode of the class to be loaded can be determined. Among them, corresponding preset loading modes can be set in advance for each class, so that the class can be loaded according to the preset loading mode corresponding to the class.
[0037] In some embodiments, the preset loading mode includes at least one of loading from the application data packet, calling the connector class loader to load, and calling the parent class loader to load. It is possible to sequentially determine whether the preset loading mode corresponding to the class to be loaded is loading from the application data packet, calling the connector class loader to load, or calling the parent class loader to load, so as to determine the preset loading mode of the class to be loaded.
[0038] S13: Use the preset loading mode of the class to be loaded to perform a loading process on the class to be loaded.
[0039] If the preset loading mode is loading from the application data packet, then use the loading method of loading from the application data packet to perform a loading process on the class to be loaded.
[0040] If the preset loading mode is calling the connector class loader to load, then use the loading method of calling the connector class loader to load to perform a loading process on the class to be loaded.
[0041] If the preset loading mode is calling the parent class loader to load, then use the loading method of calling the parent class loader to load to perform a loading process on the class to be loaded.
[0042] In some embodiments, each preset loading mode may correspond to its own class loader, so as to use the corresponding class loader to perform a loading process on the class to be loaded.
[0043] Among them, a class loader is a logical unit that loads Java classes into the virtual machine. The class loader is mainly responsible for querying and loading class files in the virtual machine. The class loader loads the data structure of the class during operation by parsing the binary file, and then calls it. When the virtual machine needs to load a class, the class loader will search for the bytecode file corresponding to the class, then load this bytecode file, and extract the required data information and store it in memory.
[0044] A class loader can be used to dynamically load Java bytecode files into the JVM memory space. In some embodiments, the JVM may include a Bootstrap class loader, an Extension class loader, and a System class loader.
[0045] Bootstrap class loader: It mainly loads the classes of the JVM itself. The bootstrap class loader is a class loader implemented in native code, which is responsible for loading the core class libraries under <Java_Runtime_Home> / lib or the Jar packages specified by the -Xbootclasspath option into memory.
[0046] Extension class loader: It is used to load the classes in the extension libraries of the JVM. The extension class loader is implemented by Sun's ExtClassLoader (sun.misc.Launcher$ExtClassLoader). It is responsible for loading the class libraries in <Java_Runtime_Home> / lib / ext or the locations specified by the system variable -Djava.ext.dir into memory.
[0047] System class loader: It is responsible for loading the class libraries specified by the user path (Classpath). It is implemented by Sun's AppClassLoader (sun.misc.Launcher$AppClassLoader). It is responsible for loading the class libraries in the directories pointed to by the system class path Java-Classpath or the -Djava.class.path variable into memory.
[0048] In some embodiments, when the preset loading mode includes calling the connector class loader for loading, it can be determined whether a connector plugin description file corresponding to the class to be loaded is provided in the application data packet; if it is determined that a connector plugin description file corresponding to the class to be loaded is provided, the connector plugin description content in the connector plugin description file is read; based on the connector plugin description content, a plugin class loader is created to perform the loading process on the class to be loaded.
[0049] In some embodiments, when the preset loading mode includes loading from the application data packet, a preset access method can be called to read the loading resources from the application data packet and perform the loading process on the class to be loaded. Among them, the preset access method can include the findClass() method.
[0050] In some embodiments, when the preset loading mode includes calling the parent class loader for loading, the parent class loader corresponding to the class to be loaded can be called to perform the loading process on the class to be loaded.
[0051] In this embodiment, by receiving a loading request for a class to be loaded, since a preset loading mode is determined based on the naming information of the class to be loaded, and the preset loading mode includes loading from an application data packet, calling a connector class loader to load, and calling a parent class loader to load, it is possible to use the determined preset loading mode of the class to be loaded to perform a loading process on the class to be loaded, and the class conflict problem during the class loading process can be reduced.
[0052] In some embodiments, refer to Figure 2 , step S12 above, determining the preset loading mode of the class to be loaded based on the naming information of the class to be loaded may include the following steps:
[0053] S121: Based on the naming information of the class to be loaded, determine whether the class to be loaded is a connector class.
[0054] Before this step, the findLoadedClass() method can be called to check whether the class to be loaded has been loaded. If it has not been loaded, then execute this step S121.
[0055] In some embodiments, the findLoadedClass() method can check whether the class corresponding to the fully qualified name of the class to be loaded has been loaded. If the check result is that it has not been loaded, then execute this step S121. If the check result is that it has been loaded, then determine whether the return value of the resolve parameter is true. If the resolve return value is true, then call the resolveClass() method to link the class to be loaded. If the resolve return value is false, then return the Class object of the class to be loaded.
[0056] In some embodiments, a name can be set for the connector class in advance, and the name can be represented in the form of a "string", so that each connector class has its own corresponding name. The connector class can be a Flink connector class. By determining whether the naming information (such as the fully qualified name) of the class to be loaded contains the string corresponding to the Flink connector class, if it contains, it is considered that the class to be loaded is a connector class, otherwise, it is not a connector class.
[0057] In step S121, if it is determined that the class to be loaded is a connector class, then execute step S122.
[0058] In step S121, if it is determined that the class to be loaded is not a connector class, then execute step S123.
[0059] S122: Determine that the preset loading mode of the class to be loaded is to load from an application data packet.
[0060] The class to be loaded is a connector class. It is determined that the preset loading mode of the class to be loaded is to load from the application data packet, and the class to be loaded can be loaded in the Jar package of the Flink application.
[0061] S123: Based on the naming information of the class to be loaded, determine whether the preset fields of the class to be loaded are in the preset set.
[0062] Among them, the preset fields include a preset number of fields starting with a prefix, and the preset set includes fields starting with the prefixes of multiple classes loaded from the parent class loader.
[0063] The classes that need to be loaded from the parent class loader are those for which the class loader in the application server will delegate to the parent class loader for class loading, that is, it will preferentially load from the parent class loader of the parent class. For example, classes with package names starting with "javax.", "java.", etc. can be classes loaded from the parent class loader. The fields starting with the prefixes or the fully qualified class names of all classes loaded from the parent class loader can be added to this preset set. This preset set can be the alwaysParentFirstPatterns set.
[0064] Based on the naming information of the class to be loaded, it can be determined whether the preset fields of the class to be loaded are in the preset set to determine whether the class to be loaded is a class loaded from the parent class loader.
[0065] In some embodiments, it can be determined whether the fully qualified name of the class to be loaded starts with a prefix in the alwaysParentFirstPatterns set. If so, it is determined that the preset fields are in the preset set; if not, it is determined that the preset fields are not in the preset set.
[0066] In this step S123, if it is determined that the preset fields are in the preset set, then execute the following step S124.
[0067] In this step S123, if it is determined that the preset fields are not in the preset set, then execute step S122.
[0068] S124: Determine that the preset loading mode of the class to be loaded is to call the parent class loader to load.
[0069] Since the fully qualified name of the class to be loaded starts with a prefix in the alwaysParentFirstPatterns set, it can be indicated that the class to be loaded is a class loaded from the parent class loader, and thus determine that the preset loading mode of the class to be loaded is to call the parent class loader to load.
[0070] The loading mode of loading by calling the parent class loader follows Java's parent delegation model. When a user needs to load a class, the loading request for that class will be delegated to the parent class loader to complete. For the bootstrap class loader, extension class loader, and system class loader, all loading requests should ultimately be passed to the top-level bootstrap class loader. Only when the parent loader feedbacks that it cannot complete the loading request for that class will the child loader load the class. For example, if class B is referenced in class A, the Java virtual machine will use the class loader that loaded class A to load class B.
[0071] In this embodiment, by determining whether the class to be loaded is a connector class and then determining whether the preset field of the class to be loaded is in the preset set, the class to be loaded is preferentially loaded from the Jar of the Flink application, and the class to be loaded can be found according to the loading order of the class to be loaded, optimizing the class loading strategy of Flink, thereby avoiding the compatibility issues related to the dependencies of the Flink framework that may occur when the class to be loaded is loaded.
[0072] In some embodiments, for step S12 above, based on the naming information of the class to be loaded, the preset loading mode of the class to be loaded is determined. The present application provides the following embodiments. Please refer to Figure 3 , Figure 3 is a schematic flowchart of the second embodiment of the class loading method of the present application. The method may include the following steps:
[0073] S21: Based on the naming information of the class to be loaded, determine whether the class to be loaded is a connector class.
[0074] In this step S21, if it is determined that the class to be loaded is a connector class, then step S22 is executed.
[0075] In this step S21, if it is determined that the class to be loaded is not a connector class, then the following step S27 is executed.
[0076] S22: Determine whether the class to be loaded is found in the application data packet.
[0077] Since the class to be loaded is a connector class, the findClass() method can be called to load the class to be loaded in the Jar package of the Flink application. Among them, the findClass() method is available in the java.lang package. The findClass() method is used to find a class with a given binary class name and is a non-static method that can be accessed through the class object.
[0078] If the class to be loaded is found in the Jar package of the Flink application, it is determined that the class to be loaded is found in the application data packet; otherwise, it is determined that the class to be loaded is not found in the application data packet.
[0079] In step S22, if it is determined that the class to be loaded is found, step S23 is executed.
[0080] In step S22, if it is determined that the class to be loaded is not found, step S24 is executed.
[0081] S23: Determine that the preset loading mode of the class to be loaded is to load from the application data packet.
[0082] If the class to be loaded is found in the Jar package of the Flink application, it can be determined that the preset loading mode of the class to be loaded is to load from the application data packet. Among them, the mode of loading from the application data packet can perform loading processing on the read class to be loaded to return the Class object of the class to be loaded.
[0083] In some embodiments, when the preset loading mode includes loading from the application data packet, a preset access method can be called to read the loading resource from the application data packet and perform loading processing on the class to be loaded. Among them, the preset access method can include the findClass() method.
[0084] S24: Determine whether the connector plugin description file corresponding to the class to be loaded is provided in the application data packet.
[0085] Since the class to be loaded is not found in the application data packet and cannot be loaded from the application data packet, the connector class loader can be called to load the class to be loaded. It can continue to determine whether the connector plugin description file corresponding to the class to be loaded is provided in the application data packet.
[0086] In some embodiments, the connector class loader corresponding to the connector class can be a plugin class loader. The plugin build package of the plugin class loader is a connector Jar package, and each plugin build package has a unique connector plugin description file. After running the Jar package of the Flink application, the corresponding connector class loader can be dynamically created by reading the connector plugin description file in the Jar package of the Flink application.
[0087] In some embodiments, since the class to be loaded is not found in the application data packet, it can be determined whether the connector plugin description file corresponding to the class to be loaded is provided in the application data packet (such as the Jar package of the Flink application). If the connector plugin description file corresponding to the class to be loaded is provided, the corresponding connector class loader can be created to perform loading processing on the class to be loaded. If the connector plugin description file corresponding to the class to be loaded is not provided, it can be returned that the connector class loader is empty, that is, the connector class loader cannot be used to load the class to be loaded.
[0088] In step S24, if the connector plugin description file corresponding to the class to be loaded is provided, step S25 is executed.
[0089] In step S24, if the connector plugin description file corresponding to the class to be loaded is not provided, step S26 is executed.
[0090] S25: Determine that the preset loading mode of the class to be loaded is to call the connector class loader for loading.
[0091] Since it is determined whether the connector plugin description file corresponding to the class to be loaded is provided in the application data packet, the preset loading mode of the class to be loaded can be determined to be to call the connector class loader for loading.
[0092] In some embodiments, when the preset loading mode includes calling the connector class loader for loading, the connector plugin description content in the connector plugin description file can be read. Based on the connector plugin description content, a plugin class loader is created to perform the loading process on the class to be loaded. Specifically, according to the connector plugin description content read from the connector plugin description file, the corresponding connector plugin build package can be located. Thus, a connector plugin metadata description is created, where the connector plugin metadata description can include information such as the plugin Id (Identity Document), the URL path (Uniform Resource Locator) where the plugin build package is located, etc. A plugin class loader is created for the connector based on the connector plugin metadata description to return the called connector class loader.
[0093] S26: Determine that the preset loading mode of the class to be loaded is to call the parent class loader for loading.
[0094] Since it is determined whether the connector plugin description file corresponding to the class to be loaded is provided in the application data packet, the preset loading mode of the class to be loaded is determined to be to call the parent class loader for loading.
[0095] In some embodiments, when the preset loading mode includes calling the parent class loader for loading, the parent class loader corresponding to the class to be loaded can be called to perform the loading process on the class to be loaded.
[0096] S27: Based on the naming information of the class to be loaded, determine whether the preset fields of the class to be loaded are in the preset set.
[0097] Among them, the preset fields include a preset number of fields starting with a prefix, and the preset set includes fields starting with the prefixes of multiple classes loaded from the parent class loader.
[0098] In step S27, if it is determined that the preset fields are in the preset set, it is determined that the preset loading mode of the class to be loaded is to call the parent class loader for loading, and step S26 is executed.
[0099] In step S27, if it is determined that the preset field is not in the preset set, it is determined that the preset loading mode of the class to be loaded is to load from the application data packet, and then step S22 is executed.
[0100] In this embodiment, by determining whether the class to be loaded is a connector class, the class to be loaded can be preferentially loaded from the application data packet (the Jar package of the Flink application), then the connector class loader is called to load, and finally the parent class loader is called to load the class to be loaded. This class loading order can effectively reduce the dependency of the Flink application's Jar package and the related class conflict problems of the Flink framework lib directory dependency, optimize the Flink class loader, and effectively improve the efficiency of loading and processing the class to be loaded.
[0101] In addition, by using a separate plug-in class loader (connector class loader) to load different connectors, a dynamic creation of the Flink connector plug-in class loader is achieved, which can reduce the class loading conflict problems existing between different Flink connectors and achieve isolated loading of classes.
[0102] In some embodiments, for step S12 above, based on the naming information of the class to be loaded, the preset loading mode of the class to be loaded is determined. The following embodiments are provided in this application. Please refer to Figure 4 , Figure 4 is a schematic flowchart of the third embodiment of the class loading method of this application. The method may include the following steps:
[0103] S31: Based on the naming information of the class to be loaded, determine whether the preset field of the class to be loaded is in the preset set.
[0104] Among them, the preset field includes a preset number of fields starting with a prefix, and the preset set includes fields starting with the prefixes of multiple classes loaded from the parent class loader.
[0105] In step S31, if the preset field is in the preset set, then step S32 is executed.
[0106] In step S31, if the preset field is not in the preset set, then step S33 is executed.
[0107] S32: Determine that the preset loading mode of the class to be loaded is to call the parent class loader to load.
[0108] S33: Based on the naming information of the class to be loaded, determine whether the class to be loaded is found in the application data packet.
[0109] In step S33, if the class to be loaded is found, then step S34 is executed.
[0110] In step S33, if the class to be loaded is not found, then step S35 is executed.
[0111] S34: Determine that the preset loading mode of the class to be loaded is to load from the application data packet.
[0112] S35: Determine whether the connector plugin description file corresponding to the class to be loaded is provided in the application data packet.
[0113] In this step S35, if the connector plugin description file corresponding to the class to be loaded is provided, then execute step S36.
[0114] In this step S35, if the connector plugin description file corresponding to the class to be loaded is not provided, then determine that the preset loading mode of the class to be loaded is to call the parent class loader to load, and execute step S32.
[0115] S36: Determine that the preset loading mode of the class to be loaded is to call the connector class loader to load.
[0116] The specific implementation process of the steps in this embodiment can refer to the specific implementation process of the above embodiment, which will not be elaborated here.
[0117] In this embodiment, by determining whether the preset field of the class to be loaded is in the preset set, it is possible to preferentially determine whether the class to be loaded is a class that needs to be loaded by the parent class loader, and at the same time, it is also possible to preferentially detect the classes loaded by the parent class loader, then determine whether the class to be loaded is found in the application data packet, then load from the application data packet, and call the connector class loader to load, which can reduce the class loading conflict problem existing between different connectors and improve the efficiency of loading and processing the class to be loaded.
[0118] For the above embodiment, the present application also provides a class loading device. Please refer to Figure 5 , Figure 5 is a schematic structural diagram of an embodiment of the class loading device of the present application. The class loading device 40 includes a receiving module 41, a loading mode determination module 42, and a loading module 43. Among them, the receiving module 41, the loading mode determination module 42, and the loading module 43 are connected.
[0119] The receiving module 41 is used to receive a loading request for the class to be loaded.
[0120] The loading mode determination module 42 is used to determine the preset loading mode of the class to be loaded based on the naming information of the class to be loaded; wherein, the preset loading mode includes at least one of loading from the application data packet, calling the connector class loader to load, and calling the parent class loader to load.
[0121] The loading module 43 is used to perform a loading process on the class to be loaded by using the preset loading mode of the class to be loaded.
[0122] In some embodiments, the loading mode determination module 42 is configured to determine whether the class to be loaded is a connector class based on the naming information of the class to be loaded; if the class to be loaded is a connector class, it is determined that the preset loading mode of the class to be loaded is to load from the application data packet.
[0123] In some embodiments, after the loading mode determination module 42 is configured to determine that the preset loading mode of the class to be loaded is to load from the application data packet, it determines whether the class to be loaded is found in the application data packet; if the class to be loaded is not found, it is determined that the preset loading mode of the class to be loaded is to call the connector class loader for loading.
[0124] In some embodiments, after the loading mode determination module 42 is configured to determine that the preset loading mode of the class to be loaded is to call the connector class loader for loading, it determines whether the connector plug-in description file corresponding to the class to be loaded is provided in the application data packet; if the connector plug-in description file corresponding to the class to be loaded is not provided, it is determined that the preset loading mode of the class to be loaded is to call the parent class loader for loading.
[0125] In some embodiments, when the loading mode determination module 42 determines that the class to be loaded is not a connector class, it determines whether the preset fields of the class to be loaded are in the preset set based on the naming information of the class to be loaded; wherein, the preset fields include a preset number of fields starting with a prefix, and the preset set includes fields starting with the prefixes of multiple classes loaded from the parent class loader. If the preset fields are in the preset set, it is determined that the preset loading mode of the class to be loaded is to call the parent class loader for loading; if the preset fields are not in the preset set, it is determined that the preset loading mode of the class to be loaded is to load from the application data packet.
[0126] In some embodiments, the loading mode determination module 42 is configured to determine whether the preset fields of the class to be loaded are in the preset set based on the naming information of the class to be loaded; wherein, the preset fields include a preset number of fields starting with a prefix, and the preset set includes fields starting with the prefixes of multiple classes loaded from the parent class loader. If the preset fields are in the preset set, it is determined that the preset loading mode of the class to be loaded is to call the parent class loader for loading; if the preset fields are not in the preset set, it determines whether the class to be loaded is found in the application data packet based on the naming information of the class to be loaded. If the class to be loaded is not found, it is determined that the preset loading mode of the class to be loaded is to call the connector class loader for loading; if the class to be loaded is found, it is determined that the preset loading mode of the class to be loaded is to load from the application data packet.
[0127] In some embodiments, when the loading module 43 is used for a preset loading mode including invoking the connector class loader for loading, it determines whether a connector plugin description file corresponding to the class to be loaded is provided in the application data packet; if it is determined that a connector plugin description file corresponding to the class to be loaded is provided, it reads the connector plugin description content in the connector plugin description file; based on the connector plugin description content, it creates a plugin class loader to perform loading processing on the class to be loaded.
[0128] In some embodiments, when the loading module 43 is used for a preset loading mode including loading from the application data packet, it invokes a preset access method to read loading resources from the application data packet and performs loading processing on the class to be loaded.
[0129] In some embodiments, when the loading module 43 is used for a preset loading mode including invoking the parent class loader for loading, it invokes the parent class loader corresponding to the class to be loaded to perform loading processing on the class to be loaded.
[0130] For the specific implementation manners of this embodiment, reference may be made to the implementation processes of the above embodiments, which will not be elaborated herein.
[0131] For the above embodiments, the present application provides a computer device. Please refer to Figure 6 , Figure 6 which is a schematic structural diagram of an embodiment of the computer device of the present application. The computer device 50 includes a memory 51 and a processor 52. Among them, the memory 51 and the processor 52 are coupled to each other. Program data is stored in the memory 51, and the processor 52 is configured to execute the program data to implement the steps in any one of the above-described class loading method embodiments.
[0132] In this embodiment, the processor 52 may also be referred to as a CPU (Central Processing Unit). The processor 52 may be an integrated circuit chip with signal processing capabilities. The processor 52 may also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The general-purpose processor may be a microprocessor or the processor 52 may also be any conventional processor, etc.
[0133] For the specific implementation manners of this embodiment, reference may be made to the implementation processes of the above embodiments, which will not be elaborated herein.
[0134] For the method of the above embodiments, it may be implemented in the form of a computer program. Therefore, the present application proposes a storage device. Please refer to Figure 7 , Figure 7It is a schematic structural diagram of an embodiment of the storage device of the present application. In the storage device 60, program data 61 that can be run by a processor is stored, and the program data 61 can be executed by the processor to implement the steps of any embodiment of the above-mentioned class loading method.
[0135] For the specific implementation manners of this embodiment, reference may be made to the implementation processes of the above-mentioned embodiments, which will not be elaborated herein.
[0136] The storage device 60 of this embodiment may be a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk, or an optical disc, etc., which can store the program data 61, or may also be a server storing the program data 61. The server can send the stored program data 61 to other devices for running, or can also run the stored program data 61 by itself.
[0137] In several embodiments provided by the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation manners described above are only illustrative. For example, the division of modules or units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces. The indirect couplings or communication connections of the devices or units can be in electrical, mechanical or other forms.
[0138] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they can be located in one place, or can also be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0139] In addition, the functional units in each embodiment of the present application can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.
[0140] When the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage device, which is a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing an electronic device (which may be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the methods in various embodiments of the present application.
[0141] Obviously, those skilled in the art should understand that the above-mentioned modules or steps of the present application can be implemented by a general-purpose computing device. They can be concentrated on a single computing device or distributed on a network composed of multiple computing devices. Optionally, they can be implemented by program codes executable by the computing device. Thus, they can be stored in the storage device and executed by the computing device, or they can be separately fabricated into individual integrated circuit modules, or multiple modules or steps among them can be fabricated into a single integrated circuit module to be implemented. In this way, the present application is not limited to any specific combination of hardware and software.
[0142] The above are only the embodiments of the present application, and do not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made by using the content of the specification and drawings of the present application, or directly or indirectly applied in other related technical fields, shall be equally included in the patent protection scope of the present application.
Claims
1. A class loading method, characterized in that, The method includes: Receiving a loading request for a class to be loaded; Based on the naming information of the class to be loaded, determining a preset loading mode for the class to be loaded; wherein, the preset loading mode includes at least one of loading from an application data packet, invoking a connector class loader to load, and invoking a parent class loader to load; the connector class loader includes a plug-in class loader; Using the preset loading mode of the class to be loaded to perform a loading process on the class to be loaded; Wherein, the determining the preset loading mode for the class to be loaded based on the naming information of the class to be loaded includes: Based on the naming information of the class to be loaded, determining whether the class to be loaded is a connector class; If the class to be loaded is a connector class, determining the preset loading mode for the class to be loaded as loading from the application data packet; determining whether the class to be loaded is found in the application data packet; If the class to be loaded is not found, determining the preset loading mode for the class to be loaded as invoking the connector class loader to load; determining whether a connector plug-in description file corresponding to the class to be loaded is provided in the application data packet; If the connector plug-in description file corresponding to the class to be loaded is not provided, determining the preset loading mode for the class to be loaded as invoking the parent class loader to load; Alternatively, the determining the preset loading mode for the class to be loaded based on the naming information of the class to be loaded includes: Based on the naming information of the class to be loaded, determining whether a preset field of the class to be loaded is in a preset set; wherein, the preset field includes a preset number of fields starting with a prefix, and the preset set includes fields starting with the prefixes of multiple classes loaded from the parent class loader; If the preset field is in the preset set, determining the preset loading mode for the class to be loaded as invoking the parent class loader to load; If the preset field is not in the preset set, based on the naming information of the class to be loaded, determining whether the class to be loaded is found in the application data packet; If the class to be loaded is not found, determining the preset loading mode for the class to be loaded as invoking the connector class loader to load; If the class to be loaded is found, determining the preset loading mode for the class to be loaded as loading from the application data packet.
2. The method according to claim 1, wherein The method further includes: If the class to be loaded is not a connector class, based on the naming information of the class to be loaded, determining whether a preset field of the class to be loaded is in a preset set; wherein, the preset field includes a preset number of fields starting with a prefix, and the preset set includes fields starting with the prefixes of multiple classes loaded from the parent class loader; If the preset field is in the preset set, determining the preset loading mode for the class to be loaded as invoking the parent class loader to load; If the preset field is not in the preset set, determining the preset loading mode for the class to be loaded as loading from the application data packet.
3. The method according to claim 1, wherein The preset loading mode includes invoking the connector class loader to load; the using the preset loading mode of the class to be loaded to perform a loading process on the class to be loaded includes: Determine whether the application data packet provides a connector plugin description file corresponding to the class to be loaded; If it is determined that the application data packet provides a connector plugin description file corresponding to the class to be loaded, read the connector plugin description content in the connector plugin description file; Based on the connector plugin description content, create a plugin class loader to perform a loading process on the class to be loaded.
4. The method according to claim 1, characterized in that The preset loading mode includes loading from the application data packet; using the preset loading mode of the class to be loaded to perform a loading process on the class to be loaded includes: Call a preset access method to read a loading resource from the application data packet and perform a loading process on the class to be loaded.
5. The method according to claim 1, characterized in that, The preset loading mode includes calling the parent class loader to load; using the preset loading mode of the class to be loaded to perform a loading process on the class to be loaded includes: Call the parent class loader corresponding to the class to be loaded to perform a loading process on the class to be loaded.
6. A computer device, characterized in that, It includes a memory and a processor that are mutually coupled. Program data is stored in the memory, and the processor is configured to execute the program data to implement the steps of the method according to any one of claims 1 to 5.
7. A storage device, characterized in that, There is program data that can be run by a processor, and the program data is used to implement the steps of the method according to any one of claims 1 to 5.