Performance issues have become increasingly valued. Since Java itself has garbage collection mechanism, it does not need to maintain memory like C, so many programmers believe that there is no memory leak, so In the programming process, use various objects, in fact, this will give the program to bring potentially difficult to discover performance costs and maintenance costs. Some frequent problems: 1) Release the object: See "Java memory leak "To understand the working principle and mechanism of JVM; arraylist al = new arraylist (); for (int i = 0; i <200; i ) {Object o = new object (); oName = 1; o.ID = 1; Al.Add (o);} The above code is still referenced by Al, not released, will not be recycled. Therefore, it is necessary to correct: arraylist al = new arraylist (); for (int i = 0; i <200; i ) {Object o = new object (); .n = 1; o.id = 1; al .add ( o); o = null;}: example 1: ObjstackClass objstack {private object [] stack; private int index; public void push (Object O) {stack [index] = O; index ;} Public Object Pop () {index-; return stack [index];} // ...} Now create a capacity of 10 object, then call 8 PUSH methods to add objects to it, then the index value is 8. What happened now after considering the POP method three times? At this time, the index value is 5, but please note that there is no other change in addition to this index value. Although the POP method reduces the index value, it is actually a reference to those objects. Calling a POP method often means that those objects should be collected (most of the situation, even if it is not right, it is also after using the object later). However, since the stack still retains a reference to the object, it cannot be collected. These objects can only be collected only after calling PUSH. The correct POP is implemented as follows: Public Object Pop () {index-; object o = stack [index]; stack [index] = null; returno;} In this version of the POP method, when the reference is returned, the stack Deleting the reference to them so that the garbage collector can recover them later. In your own code, for those who don't need it, don't reference them! The execution of the program has greatly received the impact of available memory, the less memory, the more the number of garbage collection, which will greatly harm performance.
2) String string connection string cannot change the length, the connection interpretation of the symbol uses the StringBuffer object implementation, resulting in a plurality of objects, thus using the stringBuffer.Append () method for string connections; 3) Change the code structure, compile the code structure, from Java compilation implementation Angle considerations such as: for (int i = 0; i 6) The database connection is turned off after the opening is opened. It is necessary to promote this idea. Each method is responsible for releasing the resources it gets. See http://www-900.ibm.com/developerworks/cn/java/j-diag/part11/index. SHTML (splitclener error mode :) Mode: Split Cleaner Symptoms: The program does not manage resources correctly, and it is expressed as leaks or prematurely releases them. Causes: Some execution paths of the program do not do their work: release resources Just once. Treatment and preventive measures: Move the code responsible for the release of resources to the same method of obtaining resources. Such as: conn.getConnection (); conn.close () is done in the same method body; 7) In the finally method Turning off connection 8) Processing the unusual, print, or logging logs of the connection failure (including time, source, problem description, possible solution) to find .resource: 1) Inside Java Virtual Machine2 Java Performance Tools: JProbe, Optimizer