- 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.
- Allocate reasonable memory space whenever possible when declaring an object. For example, the default space size of StringBuilder is 16 characters.
- 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.
- 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.
- 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