Multithreading, collections, network programming, memory optimization, buffering, spring, design patterns, software engineering, 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++) {
...
}
If size=1000, you can reduce the system call overhead of size () by 1000 times, 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 whenever possible (use a class with buffer instead of a class without buffer, BufferedReader, BufferedWriter, Bufferedinputstream)
10. SQL optimization, stored procedures, views, connection pooling (C3P0, DBCP)
11, Database data classification storage
Store frequently accessed data and low-frequency data, respectively, into different partitions, or even to different database servers, in order to fit into the allocation of hard disk I/O and system I/O.
12. Cache Policy
If some data is to be read from the database frequently, and the data does not change frequently, the data can be cached in the system and read the cache directly, instead of frequently accessing the database to read the data.
Caching work can read the data one time during system initialization, especially some read-only data, update the database content when the data is updated, and update the cached data values.
Java commonly 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 you manually set it to null after the object is used (avoid memory overflow).
Java Program Performance Optimization tips