Java Performance optimization

Source: Internet
Author: User
  1. Reuse objects as much as possible, rather than create new ones. Because the object's new time is 980 times times the value of the assignment, the time to create a new decimal group is 3,100 times times the value of the assignment time.
  2. Allocate reasonable memory space whenever possible when declaring an object. For example, the default space size of StringBuilder is 16 characters.
  3. Although Java can be defined and initialized anywhere, it is best to initialize it only within the scope of the variable, saving the overhead of the system.
  4. Avoid generating objects or variables that are less-used or short-life-cycle. For this scenario, an object buffer pool is defined. It is much less expensive to manage an object buffer pool than to generate and reclaim objects frequently.
  5. Abnormal:
    • Avoid logical use of the application Try/catch
      If you can use If,while and other logical statements to deal with, then as far as possible without the Try/catch statement
    • reusing exceptions
      When the exception must be handled, the exception object that already exists is reused whenever possible. It takes most of the time to generate an exception object in the handling of the exception.

Java Performance optimization

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.