DBCP used for a period of time, in the case of concurrency is relatively large, there is no problem, at least to meet the requirements of the current network system. Just a short time ago, there was a weird problem:
Start the application, can access the database, but after a period of time, about two hours or so, the system will appear to access the phenomenon of "stuck", with the Web page open, constantly in the loading state, is not loaded out.
Through the test, the link to the database to locate the problem, because all are running for a period of time on the "Stuck" state, through the previous experience immediately judge, whether it is because a thread hangs, so the next thread all stuck here, because this dbcp used for some time, think his problem is not big, If there is a problem, it should have appeared long ago. So start with the code. After detailed troubleshooting and testing, but also found that the code is not a problem, almost all of the complex or interference code is removed, or will appear this problem, by looking at the log, there is no error phenomenon, it is puzzled, there is a problem, but do not error, how to return.
Later, I firmly believe that it is the dbcp of the problem, back to the previous search DBCP data, there are said about the dbcp have a bug problem, I thought it was this problem caused? I immediately search for related resources, there is no specific information, because the system does not have error messages. Because the system is about to go online, this problem can not solve, I want to sleep is not good, so I was this problem reduced my sleep quality. The next day, I further detailed troubleshooting log information, found last night linked database error message: Java.sql.SQLException:Io exception: Connection timeout.
Ohmy God, is not the database problem, not possible, I last night ruled out the database server problems, in the careful examination of log information, found that the free link is there, why can not even it. Again found today can connect to the database, and then look at the log, idle number 0 and 1 wandering, began a little clue, with the doubt Google and Baidu a bit, and then combine their own test, the original is this: The program started when the new data source is not used, over the database time-out, will not get the real connection, Just over there the death timed out. It is also because there is no understanding of the dbcp, so before the configuration of the direct use of the line, and the use of a long period of time without problems, it is more certain of this configuration information. Before the system is not a problem, because the system 24 hours of total access, and the amount is not small, so the connection pool connection is always in use, no more than the database session link timeout time, and the number of connections more than the number of idle, is to regain new links, even if the idle access, the new will be accessed. The invalid link is just waiting for the timeout, in fact, the problem already exists, but I did not pay attention to it. Fortunately, the problem found, let me have a deeper understanding of the dbcp.
Later processing is to add more testwhileidle, Timebetweenevictionrunsmillis, Numtestsperevictionrun, Minevictableidletimemillis parameters such as tuning, probably more than the dbcp of the monitoring thread, let him check the validity of the data source connection, but also in conjunction with their own database and other environment configuration.
Specific configuration parameters can refer to the link:
http://agapple.iteye.com/blog/791943
Http://www.blogjava.net/aoxj/archive/2008/02/19/180704.html
Finally to remind yourself: don't impetuous, be careful.