1, when generating objects, reasonable allocation of space and size:new ArrayList (+);
2. Optimize for loop:
Vector vect = new vector (1000);
for (int i=0; i<vect.size (); i++) {}
Rewritten as:
int size = Vect.size ();
for (int i=0; i<size; i++) {}
If you size=1000, you can reduce The system call overhead of the size () of three times , avoiding repeated calls to the loop body.
3. New An instance object,wherenew is located (try to create the object when used)
4. Exception Handling Techniques
5. Use local variables and static variables as much as possible
6, try not to use multi-threaded synchronization
7. Use the API provided by Java itself as much as possible
8. Minimize I/O Operations (console, log)
9. Use the cache stream as much as possible (use the class with buffer instead of the classwithout buffer ,bufferedreader, Bufferwriter , 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 reasonably allocate 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, read the cache directly when used, 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 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 using large data objects, it is recommended that after the object is used, manually set to null(avoid memory).
Use the base type as much as possible instead of the object type. For example: use intinstead of Integer.
Java Code optimization Strategy