Java Program Performance Optimization tips

Source: Internet
Author: User
Tags connection pooling

Multithreading, collections, network programming, memory optimization, buffering, spring, design patterns, software project, programming ideas

1. When generating objects, allocate space and size reasonably
New ArrayList (100);

2. Optimize FOR loop
Vector vect = new vector (1000);
for (inti=0; I ...
}
The For loop part is rewritten as:
int size = Vect.size ();
for (int i=0; i>size; i++) {
...
}
Assuming size=1000, you can reduce the system call overhead of 1000 size (), avoiding repeated calls to the loop body.

3. New an instance object, where new is located (try to create the object again when it is used).

4. Exception Handling Techniques

5. Use local variables and static variables as much as possible

6, try not to apply multi-threaded synchronization

7. Use the API provided by Java itself as much as possible

8. Minimize I/O operations (console, log)

9. Use cache streams as much as possible (use a class with buffer instead of the class without buffer, BufferedReader, BufferedWriter, Bufferedinputstream)

10. SQL optimization, stored procedures, views, connection pooling (C3P0, DBCP)

11, Database data classification storage
Store frequently-visited data and low-frequency data to separate partitions. Even to different database servers to allocate hard disk I/O and system I/O in a fit.

12. Cache Policy
Suppose that some data is often read from the database. At the same time, these data do not change very often, the data can be cached in the system, the use of the direct reading of the cache. Without frequent access to the database to read data.
Caching works to read data at once when the system is initialized. In particular, some read-only data, update the database content when the data is updated, and update the cached data values at the same time.
Java frequently used cache technology products are: Redis, MemoryCache, Oscache and so on.

13. Static HTML

14, do not save too much information in the HttpSession

15. When working with large data objects, it is recommended that the object be used after it is finished. Manually set to null (avoid memory overflow).

Java Program Performance Optimization tips

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.