Microservice intelligent shutdown method and device, electronic device and storage medium

Through the parent delegation mechanism, the microservices are intelligently shut down without global switches, solving the problem of low efficiency of microservice control in the existing technology, and achieving targeted control and efficiency improvement.

CN118034805BActive Publication Date: 2024-11-19云和恩墨(北京)信息技术有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311764579.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-20
Publication Date
2024-11-19
Estimated Expiration
2043-12-20

AI Technical Summary

Technical Problem

Without global switches, it is difficult for the existing technology to control microservices in a targeted manner, resulting in the need to release multiple microservices and large-scale code modifications, which increases the scope of test regression and reduces control efficiency.

Method used

By obtaining the first object data for enabling the microservice, generating the second object data, and storing it to the storage path of the preset parent class loader using the parent delegation mechanism, priority loading is carried out to overwrite the first object data, thereby realizing microscopy Intelligent shutdown of the service reduces the range of test regression.

Benefits of technology

It realizes targeted control of the microservice function without global switches, reduces the test regression range, improves control efficiency, and disables or enables the microservice function by zero code modification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118034805B_ABST
    Figure CN118034805B_ABST
Patent Text Reader

Abstract

The present application provides a microservice intelligent shutdown method and device, an electronic device and a storage medium, which belongs to the field of Jar development technology. By obtaining first object data for starting a microservice, the first object data includes a first object name, and the first object data is located in a first storage path where a preset child class loader is located, second object data is generated according to the first object name, and the second object data is stored in a second storage path where a preset parent class loader is located. The priority relationship between the preset parent class loader and the preset child class loader is obtained, and the second object data located in the second storage path is preferentially loaded according to the priority relationship, so as to use the second object data to overwrite the first object data located in the first storage path, and shut down the microservice, the microservice can be controlled in a targeted manner.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of Jar development technology, and in particular to a microservice intelligent shutdown method and device, an electronic device, and a storage medium. Background Art

[0002] In the related art, a global switch is used to control the opening or closing of microservices. When there is no global switch control, the functions of microservices are controlled by releasing patches. This control method will issue packages to all microservices involved, resulting in the need to release multiple microservices. In addition, this control method requires a large range of code modifications, resulting in a large range of test regressions. Therefore, how to control the functions of microservices without a global switch has become an urgent problem to be solved. Summary of the invention

[0003] The main purpose of the embodiments of the present application is to propose a microservice intelligent shutdown method and device, an electronic device and a storage medium, aiming to control the functions of microservices in a targeted manner without a global switch, and reduce the scope of test regression, thereby improving control efficiency.

[0004] To achieve the above-mentioned purpose, a first aspect of an embodiment of the present application proposes a microservice intelligent shutdown method, the microservice intelligent shutdown method comprising:

[0005] Acquire first object data for starting the microservice; the first object data includes a first object name; the first object data is located in a first storage path where a preset subclass loader is located;

[0006] generating second object data according to the first object name;

[0007] The second object data is stored in a second storage path where a preset parent class loader is located;

[0008] Obtain a priority relationship between the preset parent class loader and the preset child class loader, and preferentially load the second object data located at the second storage path according to the priority relationship, so as to overwrite the first object data located at the first storage path with the second object data, and shut down the microservice.

[0009] In some embodiments, generating second object data according to the first object name includes:

[0010] Determine a second object name according to the first object name; the second object name is the same as the first object name;

[0011] An annotation class is generated according to the second object name, and the annotation class is used as the second object data.

[0012] In some embodiments, generating an annotation class according to the second object name and using the annotation class as the second object data includes:

[0013] Get a tool package for bytecode processing;

[0014] The tool data package is run to generate the annotation class based on the second object name, and the annotation class is used as the second object data.

[0015] In some embodiments, the running of the tool data package, generating the annotation class based on the second object name, and using the annotation class as the second object data includes:

[0016] Define the annotation class to be generated according to the second object name to obtain definition data;

[0017] Running the tool data package to generate the code for the definition data to obtain the annotation class;

[0018] The annotation class is used as the second object data.

[0019] In some embodiments, storing the second object data in a second storage path where a preset parent class loader is located includes:

[0020] performing data compression on the second object data to obtain compressed object data;

[0021] The compressed object data is stored in the second storage path.

[0022] In some embodiments, after shutting down the microservice, the microservice intelligent shutdown method further includes:

[0023] The second object data is deleted from the second storage path so that the preset subclass loader loads the first object data and starts the microservice.

[0024] In some embodiments, the first object data further includes a startup configuration value, and after obtaining the first object data for starting the microservice, the method further includes:

[0025] Receive microservice shutdown instructions;

[0026] In response to the microservice shutdown instruction, the startup configuration value is updated to a shutdown configuration value, and the microservice is shut down according to the shutdown configuration value.

[0027] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application proposes a microservice intelligent shutdown device, wherein the microservice intelligent shutdown device comprises:

[0028] An acquisition module, used to acquire first object data for starting the microservice; the first object data includes a first object name; the first object data is located in a first storage path where a preset subclass loader is located;

[0029] A data generating module, configured to generate second object data according to the first object name;

[0030] A storage module, used for storing the second object data in a second storage path where a preset parent class loader is located;

[0031] A microservice shutdown module is used to obtain the priority relationship between the preset parent class loader and the preset child class loader, and preferentially load the second object data located at the second storage path according to the priority relationship, so as to use the second object data to overwrite the first object data located at the first storage path, and shut down the microservice.

[0032] To achieve the above-mentioned purpose, the third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, the memory stores a computer program, and the processor implements the microservice intelligent shutdown method described in the first aspect when executing the computer program.

[0033] To achieve the above objectives, the fourth aspect of an embodiment of the present application proposes a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the microservice intelligent shutdown method described in the first aspect is implemented.

[0034] The microservice intelligent shutdown method, microservice intelligent shutdown device, electronic device and computer-readable storage medium proposed in the present application obtain first object data for starting a microservice, the first object data includes a first object name, and the first object data is located in a first storage path where a preset child class loader is located. Generate second object data according to the first object name, and store the second object data in a second storage path where a preset parent class loader is located, so as to use the parent delegation mechanism to perform intelligent shutdown of the microservice. Obtain the priority relationship between the preset parent class loader and the preset child class loader. Since the parent class loader has a higher priority than the child class loader in the parent delegation mechanism, the second object data located in the second storage path is loaded first according to the priority relationship, avoiding the loading of the first object data, so as to use the second object data to cover the first object data located in the first storage path, thereby realizing the shutdown of specific microservices and reducing the scope of test regression, thereby improving control efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1 This is a flow chart of a microservice intelligent shutdown method provided in an embodiment of the present application;

[0036] Figure 2 is another flow chart of the microservice intelligent shutdown method provided in an embodiment of the present application;

[0037] Figure 3 yes Figure 1 Flow chart of step S120 in FIG.

[0038] Figure 4 yes Figure 3 Flow chart of step S320 in FIG.

[0039] Figure 5 yes Figure 4 Flow chart of step S420 in FIG.

[0040] Figure 6 yes Figure 1 Flow chart of step S130 in FIG.

[0041] Figure 7 is a schematic diagram of a parent delegation mechanism provided in an embodiment of the present application;

[0042] Figure 8 It is a structural diagram of a microservice intelligent shutdown device provided in an embodiment of the present application;

[0043] Fig. 9 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION

[0044] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0045] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0046] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0047] In the related art, a global switch is used to control the opening or closing of microservices. When there is no global switch control, the functions of microservices are controlled by releasing patches. This control method will issue packages to all microservices involved, resulting in the need to release multiple microservices. In addition, this control method requires a large range of code modifications, resulting in a large range of test regressions. Therefore, how to control the functions of microservices without a global switch has become an urgent problem to be solved.

[0048] Based on this, the embodiments of the present application provide a microservice intelligent shutdown method, a microservice intelligent shutdown device, an electronic device and a computer-readable storage medium, which can control the functions of microservices in a targeted manner without a global switch, and reduce the scope of test regression, thereby improving control efficiency.

[0049] The microservice intelligent shutdown method, microservice intelligent shutdown device, electronic device and computer-readable storage medium provided in the embodiments of the present application are specifically illustrated by the following embodiments. First, the microservice intelligent shutdown method in the embodiments of the present application is described.

[0050] The microservice intelligent shutdown method provided in the embodiment of the present application relates to the field of Jar development technology. The microservice intelligent shutdown method provided in the embodiment of the present application can be applied to the terminal, can also be applied to the server side, and can also be software running in the terminal or the server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or it can be configured as a server cluster or distributed system composed of multiple physical servers, and can also be configured as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the microservice intelligent shutdown method, etc., but is not limited to the above forms.

[0051] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.

[0052] Most J2EE (Java 2 Platform Enterprise Edition) products are developed based on spring boot. Spring boot can enable many functions through annotations, such as enabling transactions and swagger, and can also define interceptors through annotations to implement certain functions, such as counting the number of interface accesses and the time consumed by interfaces. For microservices, after these functions of microservices are released to client production, if it is found that some functions are not needed and there is no global switch to control these functions, these functions can only be disabled by modifying the code in the form of patches, which may involve the release of dozens of microservices, and it is impossible to turn off specific functions of microservices. In the test scenario, it is necessary to test whether these dozens of microservices have functional anomalies, and the test regression range is large.

[0053] Figure 1 is an optional flowchart of the microservice intelligent shutdown method provided in the embodiment of the present application. Figure 1 The method may include but is not limited to steps S110 to S140.

[0054] Step S110, obtaining first object data for starting a microservice; the first object data includes a first object name; the first object data is located in a first storage path where a preset subclass loader is located;

[0055] Step S120, generating second object data according to the first object name;

[0056] Step S130, storing the second object data in a second storage path where the preset parent class loader is located;

[0057] Step S140, obtaining the priority relationship between the preset parent class loader and the preset child class loader, and preferentially loading the second object data located at the second storage path according to the priority relationship, so as to use the second object data to overwrite the first object data located at the first storage path, and shut down the microservice.

[0058] In step S110 of some embodiments, the first object data is the microservice data that enables the microservice function in an annotation manner, and the microservice data is the original class data used to implement the microservice function, and the original class data includes the specific data processing logic of the microservice function. The first object data includes a first object name, and the first object name is the class name of the original class that implements the microservice function. The first object data is located in the first storage path where the preset subclass loader is located. The preset subclass loader is a user-defined class loader, which belongs to the application class loader (Application ClassLoader), and is responsible for loading the application class under the user class path, and the user class path is ClassPath. For example, the microservice function is to count the number of visits, and the interceptor annotation class that implements the microservice function is @Counter. The class name, class method, class object and other information of the annotation class are the first object data, and Counte is the first object name.

[0059] See also Figure 2 In some embodiments, the first object data further includes a startup configuration value, and the startup configuration value is used to start the microservice. After step S110, the microservice intelligent shutdown method further includes:

[0060] Step S210, receiving a microservice shutdown instruction;

[0061] Step S220: In response to the microservice shutdown instruction, the startup configuration value is updated to the shutdown configuration value, and the microservice is shut down according to the shutdown configuration value.

[0062] In step S210 of some embodiments, a control interface is set for each microservice function to enable or disable the microservice function through the respective control interface. A microservice shutdown instruction is received through the control interface, and the microservice shutdown instruction is used to shut down a specific function of the microservice, and the specific function corresponds to the control interface one by one.

[0063] In step S220 of some embodiments, in response to the microservice shutdown instruction, the startup configuration value is updated to the shutdown configuration value, the shutdown configuration value is used to shut down the microservice, and the specific function of the microservice is shut down according to the shutdown configuration value. The specific function can be swagger, counting access volume, and calculating interface time consumption.

[0064] In the above steps S210 to S220, by introducing a control interface for each microservice, it is possible to close a specific microservice function.

[0065] See also Figure 3 In some embodiments, step S120 may include but is not limited to steps S310 to S320:

[0066] Step S310, determining a second object name according to the first object name; the second object name is the same as the first object name;

[0067] Step S320: Generate an annotation class according to the second object name, and use the annotation class as the second object data.

[0068] In step S310 of some embodiments, a second object name is determined according to the first object name, and the second object name is the same as the first object name, so as to generate a new class with the same class name.

[0069] In step S320 of some embodiments, a new annotation class is defined in a file of a preset format according to the second object name, and the new annotation class is used as the second object data. The new annotation class is an empty class, which is just an annotation and does not have any data processing logic. The preset format can be .txt format.

[0070] The embodiment of the present application utilizes the policy characteristics of the annotation @Retention to retain the original class and the new class, and invalidates the annotation class in a zero-code intrusion manner. Specifically, when it is necessary to access the annotation through reflection at runtime, the RUNTIME strategy is applied. Many frameworks and libraries, such as Spring, Hibernate, etc., use this strategy to read and process annotations at runtime. When the annotation needs to exist in the compiled bytecode but does not need to be accessed through reflection at runtime, the CLASS strategy is applied, which is commonly used in some frameworks or libraries, which read the annotation information when loading the class, but do not need to retain this information at runtime. When the annotation is only used at the source code level and does not need to exist in the compiled bytecode or runtime, the SOURCE strategy can be used, which is commonly used in some compile-time tools or static code analysis.

[0071] The following uses the EnableSwagger2 annotation class as an example to illustrate the difference between the original class and the new class. The original class of the EnableSwagger2 annotation class is as follows:

[0072] @Retention(RetentionPolicy.RUNTIME)

[0073] @Target({ElementType.TYPE})

[0074] @Documented

[0075] @Import({Swagger2DocumentationConfiguration.class})

[0076] public@interface EnableSwagger2{}.

[0077] The new class of the EnableSwagger2 annotation class is as follows:

[0078] @Retention(RetentionPolicy.CLASS)

[0079] @Target({ElementType.TYPE})

[0080] @Documented

[0081] public@interface EnableSwagger2{}.

[0082] Among them, @Retention(RetentionPolicy.RUNTIME) is the original class of the EnableSwagger2 annotation class, and @Retention(RetentionPolicy.CLASS) is the new class of the EnableSwagger2 annotation class. Because CLASS will be invalid at runtime, the effect of annotation invalidation can be achieved. In addition, the new class does not have @Import({Swagger2DocumentationConfiguration.class}), so the Swagger implementation class will not be introduced, further invalidating the annotation class.

[0083] The following further uses the annotation of calculating the interface time consumption defined by springboot as an example to illustrate the difference between the original class and the new class. The original class is as follows:

[0084] @Target(ElementType.METHOD})

[0085] @Retention(RetentionPolicy.RUNTIME)

[0086] public@interface TrackExecutionTime{}

[0087] The new class looks like this:

[0088] @Target(ElementType.METHOD})

[0089] @Retention(RetentionPolicy.CLASS)

[0090] public@interface TrackExecutionTime{}

[0091] You can also use the @Retention(RetentionPolicy.CLASS) feature to invalidate the annotation. Similarly, all custom or framework-provided annotations can be invalidated in this way.

[0092] Through the above steps S310 to S320, a new class with the same class name as the original class can be generated, so that the new class can be used to cover the original class and disable specific microservice functions.

[0093] See also Figure 4 In some embodiments, step S320 may include but is not limited to steps S410 to S420:

[0094] Step S410, obtaining a tool data package for bytecode processing;

[0095] Step S420 , running the tool data package, generating an annotation class based on the second object name, and using the annotation class as the second object data.

[0096] In step S410 of some embodiments, a tool data package for bytecode processing is obtained, and the tool data package is a Java Bytecode Manipulation Framework (Java ASM). It is a Java bytecode operation and analysis framework for reading, generating and converting Java classes or implementing Java class loaders. ASM can directly generate binary bytecodes, and can dynamically generate, modify and analyze the bytecodes of Java classes.

[0097] In step S420 of some embodiments, the annotation class is dynamically generated using Java ASM. Java ASM is run to generate an annotation class with the same name as the original class based on the second object name, and the annotation class is used as the second object data.

[0098] Through the above steps S410 to S420, the annotation class can be dynamically generated according to the object name.

[0099] See also Figure 5 In some embodiments, step S420 may include but is not limited to steps S510 to S530:

[0100] Step S510, defining the annotation class to be generated according to the second object name to obtain definition data;

[0101] Step S520, running the tool data package to generate code for defining data to obtain an annotation class;

[0102] Step S530: taking the annotation class as the second object data.

[0103] In step S510 of some embodiments, the second object name is filled into the preset template, the annotation class to be generated is defined, and the definition data is obtained. The definition data is stored as a file in .txt format and the file is named. The name of the file may be annotationDefineFile.txt. The preset template includes the object name and the acquisition address of the annotation class corresponding to the object name. Taking EnableSwagger2 as an example, the preset template may be:

[0104] springfox.documentation.swagger2.annotations.EnableSwagger2

[0105] com.xx.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI.

[0106] In step S520 of some embodiments, the tool data package is run based on the preset instruction, and the code related to the definition data is generated using the .txt format file to obtain the annotation class, and the annotation class is used as the second object data. The preset instruction is related to the name of the tool data package, and the preset instruction is the java-jar name. If the name of the tool data package is tools.jar, the preset instruction is java-jar tools.jar.

[0107] In step S530 of some embodiments, the code of the annotation class is used as the second object data.

[0108] In the above steps S510 to S530, a preset template can be configured through the second object name, so that the required annotation class is automatically generated through the configuration.

[0109] See also Figure 6 In some embodiments, step S130 may include but is not limited to steps S610 to S620:

[0110] Step S610, compressing the second object data to obtain compressed object data;

[0111] Step S620: store the compressed object data in the second storage path.

[0112] In step S610 of some embodiments, in order to reduce the storage space of the second object data, data compression is performed on the second object data, and the generated code is automatically compressed into a jar package to obtain compressed object data.

[0113] In step S620 of some embodiments, the embodiments of the present application use a parent delegation mechanism (ParentDelegation Mechanism) to disable microservice functions. The parent delegation mechanism is a class loading mechanism in Java. In Java, the class loader is responsible for loading the bytecode of the class and creating the corresponding Class object. The parent delegation mechanism means that when a class loader receives a class loading request, it will first delegate the request to the parent class loader to try to load it. Only when the parent class loader cannot load the class will the child class loader try to load it. This mechanism is designed to ensure that the loading of classes is orderly and to avoid repeated loading of the same class. The schematic diagram of the parent delegation mechanism is shown in Figure 7 shown. Figure 7 It includes user-defined class loader 1, user-defined class loader 2, application class loader (Application Classloader), extension class loader (Extension Classloader) and bootstrap class loader (Bootstrap Classloader). The application class loader is responsible for loading the application class under the user class path (ClassPath), the extension class loader is responsible for loading the extension class library under the %JAVA_HOME% / jre / lib / ext directory, and the bootstrap class loader is responsible for loading the core Java class library such as rt.jar, charsets.jar, etc. under the %JAVA_HOME% / jre / lib directory. User-defined class loader 1 and user-defined class loader 2 are peer class loaders. The parent delegation mechanism is to delegate class loading requests from user-defined class loader, application class loader, extension class loader and bootstrap class loader to the upper level step by step.

[0114] By using the parent delegation mechanism of java class loading, the newly generated class is placed in the ext directory, and the newly generated class will be loaded first, and the original class will not be loaded again, so as to overwrite a class in the original application. Specifically, the compressed object data is stored in the second storage path where the preset parent class loader is located, and the second storage path is the JAVA_HOME / jre / lib / ext directory.

[0115] In the above steps S610 to S620, the compressed object data is stored in a specified directory where the preset parent class loader is located, so that the compressed object data is loaded first, thereby achieving the purpose of disabling the original annotation class.

[0116] In step S140 of some embodiments, in the parent delegation mechanism, the priority of the preset parent class loader is higher than the priority of the preset child class loader. The preset parent class loader with a higher priority will preferentially load the new annotation class, and the preset child class loader with a lower priority will not load the original annotation class, so that the new annotation class will overwrite the original annotation class, thereby achieving the purpose of disabling the microservice function related to the annotation class. Specifically, the priority relationship between the preset parent class loader and the preset child class loader is obtained, and the priority relationship is used to characterize the priority of the preset parent class loader and the preset child class loader. The priority of the preset parent class loader is higher than the priority of the preset child class loader. The second object data located at the second storage path is preferentially loaded according to the priority relationship. Since the preset parent class loader has successfully loaded the second object data, in order to avoid the data of the same class name being repeatedly loaded, the preset child class loader will not load the first object data located at the first storage path, so as to use the second object data to replace the first object data located at the first storage path, close the microservice, and achieve zero code modification to disable any microservice function that has been annotated and enabled, while improving the test efficiency in the test environment. If springboot@EnableCaching turns on the cache, if a problem with the cache is found during the product launch process, the cache can be disabled using the microservice intelligent shutdown method of the embodiment of the present application.

[0117] The second object data is deleted from the second storage path, the preset parent class loader cannot load the second object data normally, and the first object data located at the first storage path will be loaded normally, so that the preset child class loader loads the first object data and starts the microservice.

[0118] If the service package released to the production environment does not disable swagger, you need to disable swagger without modifying the code. Get the method to enable swagger in the service package. The method to enable swagger is implemented through the annotation @EnableSwagger2. Use the tool to generate an annotation class with the same name, write annotations based on the file annotationDefineFile.txt, and write springfox.documentation.swagger2.annotations.EnableSwagger2 in the file annotationDefineFile.txt. Execute the command java -Djava.home=${JAVA_HOME}-jar tools.jar. After executing the command, diableAnnotation.jar will be generated, and the diableAnnotation.jar package will be automatically copied to the ${JAVA_HOME} / jre / lib / ext directory. Restart the microservice normally, use the java class loading parent delegation mechanism and @Retention(RetentionPolicy.CLASS) feature, and the newly generated class will overwrite the original class to achieve the purpose of disabling swagger.

[0119] The startup command to restart the microservice is: java -Djava.home=${JAVA_HOME}-Dannotations=springfox.documentation.swagger2.annotations.EnableSwagger2,org.springframework.cache.annotation.EnableCaching-jartools.jar. The startup command does not require the annotationDefineFile.txt file. If there are multiple startup parameters, they can be separated by commas.

[0120] See also Figure 8 The embodiment of the present application also provides a microservice intelligent shutdown device, which can implement the above-mentioned microservice intelligent shutdown method, and the device includes:

[0121] The acquisition module 810 is used to acquire first object data for starting the microservice; the first object data includes a first object name; the first object data is located in a first storage path where a preset subclass loader is located;

[0122] The data generating module 820 is used to generate the second object data according to the first object name;

[0123] A storage module 830, configured to store the second object data in a second storage path where a preset parent class loader is located;

[0124] The microservice shutdown module 840 is used to obtain the priority relationship between the preset parent class loader and the preset child class loader, and preferentially load the second object data located at the second storage path according to the priority relationship, so as to use the second object data to overwrite the first object data located at the first storage path, and shut down the microservice.

[0125] The specific implementation of the microservice intelligent shutdown device is basically the same as the specific implementation of the above-mentioned microservice intelligent shutdown method, and will not be repeated here.

[0126] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above-mentioned microservice intelligent shutdown method when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.

[0127] See also Fig. 9 , Fig. 9 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:

[0128] The processor 910 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;

[0129] The memory 920 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 920 can store an operating system and other applications. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 920, and the processor 910 calls and executes the microservice intelligent shutdown method of the embodiment of this application;

[0130] Input / output interface 930, used to implement information input and output;

[0131] Communication interface 940, used to realize communication interaction between the device and other devices, which can be realized through wired mode (such as USB, network cable, etc.) or wireless mode (such as mobile network, WIFI, Bluetooth, etc.);

[0132] bus 950 , which transmits information between the various components of the device (e.g., processor 910 , memory 920 , input / output interface 930 , and communication interface 940 );

[0133] The processor 910 , the memory 920 , the input / output interface 930 , and the communication interface 940 are connected to each other in communication within the device via a bus 950 .

[0134] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above-mentioned microservice intelligent shutdown method is implemented.

[0135] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0136] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0137] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.

[0138] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0139] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.

[0140] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0141] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0142] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as 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 mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0143] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0144] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0145] If 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 computer-readable storage medium. Based on this understanding, the technical solution of the present application, 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, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.

[0146] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.

Claims

1. Microservice intelligent shutdown method, characterized in that: The method comprises: Acquire first object data for starting the microservice; the first object data includes a first object name; the first object data is located in a first storage path where a preset subclass loader is located; generating second object data according to the first object name; The second object data is stored in a second storage path where a preset parent class loader is located; Obtaining a priority relationship between the preset parent class loader and the preset child class loader, and preferentially loading the second object data located at the second storage path according to the priority relationship, so as to overwrite the first object data located at the first storage path with the second object data, and shutting down the microservice; The generating the second object data according to the first object name comprises: Determine a second object name according to the first object name; the second object name is the same as the first object name; An annotation class is generated according to the second object name, and the annotation class is used as the second object data.

2. The microservice intelligent shutdown method according to claim 1 is characterized in that: The step of generating an annotation class according to the second object name and using the annotation class as the second object data includes: Get a tool package for bytecode processing; The tool data package is run to generate the annotation class based on the second object name, and the annotation class is used as the second object data.

3. The microservice intelligent shutdown method according to claim 2 is characterized in that: The step of running the tool data package, generating the annotation class based on the second object name, and using the annotation class as the second object data includes: Define the annotation class to be generated according to the second object name to obtain definition data; Running the tool data package to generate the code for the definition data to obtain the annotation class; The annotation class is used as the second object data.

4. The microservice intelligent shutdown method according to claim 1, characterized in that: The storing the second object data to a second storage path where a preset parent class loader is located includes: performing data compression on the second object data to obtain compressed object data; The compressed object data is stored in the second storage path.

5. The microservice intelligent shutdown method according to any one of claims 1 to 4, characterized in that: After shutting down the microservice, the microservice intelligent shutdown method further includes: The second object data is deleted from the second storage path so that the preset subclass loader loads the first object data and starts the microservice.

6. The microservice intelligent shutdown method according to any one of claims 1 to 4, characterized in that: The first object data also includes a startup configuration value. After obtaining the first object data for starting the microservice, the method further includes: Receive microservice shutdown instructions; In response to the microservice shutdown instruction, the startup configuration value is updated to a shutdown configuration value, and the microservice is shut down according to the shutdown configuration value.

7. Microservice intelligent shutdown device, characterized in that: The device comprises: An acquisition module, used to acquire first object data for starting the microservice; the first object data includes a first object name; the first object data is located in a first storage path where a preset subclass loader is located; A data generating module, configured to generate second object data according to the first object name; A storage module, used for storing the second object data in a second storage path where a preset parent class loader is located; a microservice shutdown module, configured to obtain a priority relationship between the preset parent class loader and the preset child class loader, and preferentially load the second object data located at the second storage path according to the priority relationship, so as to overwrite the first object data located at the first storage path with the second object data, and shut down the microservice; The generating the second object data according to the first object name comprises: Determine a second object name according to the first object name; the second object name is the same as the first object name; An annotation class is generated according to the second object name, and the annotation class is used as the second object data.

8. An electronic device, characterized in that The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the microservice intelligent shutdown method according to any one of claims 1 to 6 when executing the computer program.

9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the microservice intelligent shutdown method according to any one of claims 1 to 6 is implemented.