Java program performance optimization skills

Source: Internet
Author: User

Java program performance optimization skills

Multithreading, collection, network programming, memory optimization, buffering, spring, design pattern, software engineering, programming ideas

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

2. Optimize the for Loop
Vector vect = new Vector (1000 );
For (inti = 0; I <vect. size (); I ++ ){
...
}
The for loop part is rewritten:
Int size = vect. size ();
For (int I = 0; I> size; I ++ ){
...
}
If the size is 1000, the system call overhead of the size () can be reduced by 1000 times, avoiding the loop weight of the system.

3. new instance object, where new is located (try to create this object again when used ).

4. Exception Handling Skills

5. Use local variables and static variables whenever possible

6. multithreading synchronization is not applicable as far as possible

7. Use APIs provided by Java as much as possible

8. Minimize I/O operations (console and logs)

9. Use cache streams whenever possible (use classes with Buffer instead of classes without Buffer, BufferedReader, BufferedWriter, and BufferedInputStream)

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

11. Hierarchical Storage of Database Data
Store frequently accessed data and infrequently accessed data in different partitions, or even in different database servers, so that they can be integrated into and allocated hard disk I/O and system I/O.

12. Cache Policy
If some data needs to be read from the database frequently and does not change frequently, the data can be cached in the system and directly read during use, instead of frequently accessing the database to read data.
Cache can read data at one time during system initialization, especially some read-only data. when the data is updated, the database content is updated and the cached data value is updated.
Common Java cache technologies include Redis, MemoryCache, and OSCache.

13. static html

14. You do not need to save too much information in HttpSession.

15. When using a big data object, we recommend that you manually set it to null (to avoid memory overflow) after the object is used ).

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.