Lifecycle management in the Java development platform

Source: Internet
Author: User
Tags requires

The life cycle of an object is not as complex as everyone thinks. In fact, it answers two simple questions. When do I need to create an object? When did the object die out? These two problems are solved, so the life cycle problem of the object is solved.

The traditional method of object lifecycle management.

In order to have a deeper understanding of the lifecycle management method in the Java development platform, the author thinks that we need to have an understanding of the traditional life cycle management method first. Because it helps you to have a comparison, you will have a more intuitive impression of the lifecycle management approach in the Java language.

In traditional programming languages, such as the C language, it takes into account the lifecycle of objects, primarily from the execution efficiency of objects and applications. In order to pursue the maximum execution efficiency of the application, the C language requires the program developer to determine the storage space and lifecycle of the object when writing the application, either through heap money or domain-limiting variables. The advantages of this design are obvious. Because it involves the storage space and lifecycle of the object when the program is developed, there is no need to expend effort to create the object when the program is running. What the application developer needs to know is that it is easy and time-consuming to create and dispose of the object's storage space in the stack. Creating an object space on the stack requires only one assembly instruction to move the top pointer down, and another assembly instruction to move the stack top pointer up as needed to free up storage space. As a result, applications can execute at a relatively high speed, placing the allocation and release of object storage space in a more limited position.

But the biggest drawback of this management approach is that flexibility is not high. Because the exact number, lifecycle, and storage space of the object must be known when the application is developed. If you need to do two development or feature upgrades to your application, the amount of rework will be significant if you are involved in adding new objects. And for ordinary application developers, it is difficult to make an accurate estimate of the number and lifecycle of the objects needed. As you can see, this management approach ensures the maximum speed of the application, but its limitations are quite large. Not only does it have a low flexibility, but it also has higher requirements for application developers.

Second, the object lifecycle management method under the Java platform.

Under the Java language platform, it differs greatly from the traditional object management methods. Under the Java language platform, it is called a dynamic creation object. Simply put, it is not creating objects while the application is developing, but dynamically building objects on demand as the application runs. Unlike the object lifecycle above, dynamic creation of objects takes into account the number of objects that need to be created, how long their life cycle is, and what type of object they are in when the application is running. These problems can be finalized only at the moment the application code is executed. There is no need to focus on these issues during application development. As in Java language development, there is no need to create objects at first. When you need an object, you can use the New keyword to create an object.

Obviously, because the creation and extinction of objects are dynamically managed while the application is running, the flexibility is higher than the traditional static management method. When you need a new object phase, you only need to create one in your code with the new keyword without having to make changes to other content. For this reason, a language such as Java, which uses dynamic mechanisms to manage the lifecycle of objects, is often thought to be higher than the traditional C-language program in upgrading, two development. And because the object is created when it is needed, the requirements for application developers are relatively low. The threshold for application developers to enter the Java language is also much lower.

Related Article

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.