How to solve weblogic jsp problems
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 program running, 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 returned result set (Resultset), and the database connection cannot be closed in jsp.
Solution:
1. Close the database connection after the operation.
2. Try not to return the result set Resultset. You can return Vector (one field) and Hashtable (multiple fields). In this way, you can close the database in javabean.
3. if a result set (Resultset) is returned in the javabean, you can also write a connectDB (connect to the database) and closeDB (close the database) method in the javaBean, and then call connectDB () in the 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.
Use method 2
Question 2:
When running a jsp program, weblogic's memory suddenly increases and remains high. Eventually, weblogic memory is insufficient, or even becomes a machine.
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 very familiar with String, and we often use it for String connection or something, 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 () Apparently, 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 + = "";
}
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 ("");
}
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.
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