A simple example of a class of Gegacay (Hot Deployment)

Source: Internet
Author: User

The application server generally supports hot deployment, and when updating the code, it replaces the new compiled class with the old ones, and the following program executes the code in the new class. This is also implemented by a single class loader hierarchy of various application servers. So how do you implement this thermal loading function in our program? That is, if the virtual machine does not shut down (for example, one), the JVM knows to load the new class and execute the logic in the new class. The following is a simple example of a hot load, first of all, a general look at the ClassLoader.

Class loader hierarchy for standard Java initiators

1. Boot class loader (bootstrap): Load kernel APIs, such as Rt.jar (Java.lang, java.io, etc.)

2. Extended class loader (extension): Loaded default extension from Jre/lib/ext

3. Systems class Loader (System): Classes on classpath, such as com.unmi.*

Description: This is just the class loader level when the standard Java launcher runs the program, and the class loader in the application server is typically one or two layers, and is also an extension on this basis. The above class loading hierarchy exists a Top-down delegate relationship, and the delegate loading is not detailed here.

The class loader rule has three

1. Consistency rule: Class loader cannot load the same class multiple times

2. Delegate rule: The class loader always references the parent class loader before loading a class

3. Visibility rule: A class can only see other classes loaded by its class loader delegate, which is the recursive collection of the class's loader and all its parent class loaders. (This rule may not be very well understood, for example it is easy to understand, and here is not to elaborate)

The actual example demonstrates the thermal loading

1. Build the project, write the code

The front cushion should be thick enough, start with an example to explain the feeling class of Gegacay (also known as hot deployment). This example uses Eclipse to create the first two common Java projects, Testhotdeployinf and Testhotdeployimpl, respectively. Let Testhotdeployimpl rely on Testhotdeployinf Engineering, that is, in Testhotdeployimpl's build Path, the Testhotdeployinf project is selected in the Projects tag page because the The classes in the Testhotdeployimpl use the classes in the Testhotdeployinf.

Then create a new Interface (Cat.java) and a Class (Client.java) in the engineering Testhotdeployinf, respectively:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.