Five ways to optimize Java performance

Source: Internet
Author: User

one, optimization of Java performance optimization design
Design optimization is at the top of the performance optimization Approach. It often needs to be done before software Development. Before software development, The system architect should assess the potential problems and technical difficulties of the system, and give a reasonable design, because the software design and system architecture have a decisive impact on the overall design quality of the Software. therefore, Design tuning has the greatest impact on the performance of the system, assuming that the code is Optimized. JVM optimization is the "quantity" optimization of the micro-level of the system, and the optimization of the design is the optimization of the system "quality".
One of the salient features of design optimization is that it avoids the performance problem of a component, but rather improves the implementation of the component; for example, component A monitors the continuous detection time e if it occurs, and its detection behavior is bound to occupy some of the system resources, so developers have to check the frequency and resource consumption to strike a balance, Assuming that the detection frequency is too low, despite the reduction of resource consumption, but the system real-time responsiveness will be reduced, assuming that the code layer tuning, it is necessary to optimize the detection method of the implementation and requirements of the most appropriate detection frequency. for this problem we can use the Observer pattern in design mode, when event e occurs, Notifies component A by event e, which triggers the behavior of component A. Such a design fundamentally overcomes the existence of performance problems in the cycle of monitoring, fundamentally overcome the Problem.
For design optimization, designers and developers must be familiar with frequently used design methodologies, design patterns, and major performance components and often-used optimization ideas, and integrate them organically in software Systems.
note: a good system design can circumvent very many potential performance issues. therefore, spend as much time as possible on system design is the key to creating high-performance programs
two, Java Performance Optimization code optimization
Code tuning is the improvement and optimization of program code in software development, or after software Development. code optimization involves a number of coding techniques that require developers to familiarize themselves with the relevant language APIs and to properly use the relevant API or class library in the appropriate scenario. at the same time, the algorithm, The flexible use of data structures is also an important part of code Optimization.
Although the code is optimized for performance tuning from the micro, a "good" implementation and a "bad" implementation of the system is also very large. for example, the same as the implementation of the list, LinkedList and ArrayList on the random access to the performance of several levels; For example, the same is the implementation of the file read and write, using the stream method and the use of Java nio, its system can be another order of Magnitude.
therefore, Although compared with the design optimization, the author optimizes the code to be on the micro level, but it is the optimization method which has the most direct effect on the system performance.
third, JVM Optimization
Because Java software is always executed on top of the JVM virtual Machine. Optimizing the JVM virtual machine can also improve the performance of Java programs to some Extent. The JVM is usually able to perform later in software development, such as at a milestone stage in development or software Development.
As the execution platform for Java software. The parameters of the JVM will directly affect the performance of the Java Program.

For example, the Jvm's heap size, garbage collection policy, and so On.
Tuning at the JVM level. Developers are required to have a certain understanding of the Jvm's execution principle and basic memory Structure. such as the structure of heap memory, the type of gc, etc. then, according to the characteristics of the reference Program. Set a reasonable JVM startup Parameter.


Four. Database Optimization
For most application Systems. The database is an indispensable part. Java programs can connect to a database using JDBC. Tuning a database can be divided into three parts:

    • The SQL statement is optimized at the application layer;
    • Optimize the Database.
    • Optimize the database Software.

Access to the database in the application layer Optimization. Involves a lot of programming skills. Example. When querying using jdbc, you can use perparedstatement instead of statement for large numbers of SQL queries that have the same structure. To improve the efficiency of database Query. In the use Select statement, displays the name of the column specified to query, avoiding the use of *
When optimizing the database, the main purpose is to establish a database with good table Structure.

For example, in order to improve the efficiency of multi-table cascading queries, redundant fields can be used reasonably, and for large tables, it is possible to use horizontal segmentation of rows or similar techniques of Oracle partitioning, in order to improve the efficiency of data query, to establish an effective horizontal segmentation or similar Oracle partition table technology , in order to improve the efficiency of database Query. In the Select Statement. Displays the name of the column specified to query, avoiding the use of *.
When the database is Optimized. The main purpose is to create a database with a good table structure. For example, to improve the efficiency of multi-table cascading queries, redundant fields can be used Rationally. For large Tables. Ability to use row data to split horizontally, to improve the efficiency of database query, to establish an effective and issue index
five, optimization of operating system for Java performance optimization
The operating system, the means of tuning and the number of parameters may vary, for example, in mainstream Unix systems. Shared Memory Segment. semaphore, Shared Memory Maximum (shmmax). The shared memory minimum (shmmin) is a system resource that can be optimized. in addition, parameters such as the maximum number of file handles, virtual memory size, disk block size, and so on, can have an impact on the performance of the Software. configuring the Virtual Memory interface

Five ways to optimize Java performance

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.