During project creation, JSP encountered some problems during running. Now, I will summarize my problem solutions for future project reference.
Question 1:
The number of weblogic database connections keeps increasing during the running of the program, and the maximum number of connections is exceeded. As a result, the weblogic service is closed.
Cause:
After the database is operated, the database connection is not closed; or the result set Resultset is returned), and the database connection cannot be closed in JSP.
Solution:
1. Close the database connection after the operation.
2. Do not return the result set Resultset. You can return a Vector field) or Hashtable multiple fields. In this way, you can close the database in javabean.
3. if the result set Resultset is returned in javabean, you can also write a connectDB connection to the database in javaBean) and closeDB (close the database) methods, and then call connectDB in jsp ), after establishing a database connection, you can operate the database. After the database operation is complete, you can use closeDB () to close the database.
Question 2:
When running a JSP program, weblogic's memory suddenly increases and remains high. Eventually, weblogic memory is insufficient or even goes down.
Cause:
Excessive memory usage.
Solution:
1. because the data volume is large, you can use + to connect strings when operating on strings. I believe everyone is familiar with String, and we often use it to connect strings, for example:
String a = B + c file: // B, c is String
However, in actual compilation, it is as follows:
String a=new StringBuffer().append(b).append(c).toString() |
Obviously, two objects are generated unexpectedly in a simple statement:
. StringBuffer ()
. ToString returns a String
Let's compare the performance of the two programs:
Procedure 1:
StringBuffer s=new StringBuffer(); long start = System.currentTimeMillis(); for (int i=0;i<10000;i++){ s1+="a"; } long stop = System.currentTimeMillis(); System.out.println(stop-start); |
Program Segment 2:
StringBuffer s=new StringBuffer(10000);// long start=System.currentTimeMillis(); for (int i=0;i<10000;i++){ s.append("a"); } long stop=System.currentTimeMillis(); System.out.println(stop-start); |
The difference is obvious.
As to why the String connection does this, because the String cannot directly change its length, it must use the StringBuffer usage.
Therefore, we recommend that you use the append method of StringBuffer to connect strings.
2. When solving this problem, I also tried to use the above method. The effect is not very obvious (memory consumption ). Later, when a large amount of data is displayed, the out. println () method is used to directly output the data without the steps of string connection.