There are too many articles on the web about how to configure the Tomcat database connection pool. But I can't find an article that can
Tell me how to get the number of current connections for the Tomcat connection pool. If you want to monitor the health of Tomcat, this
is an important parameter. So it took me half a day to study the problem.
First looked at Tomcat's related source code, obtains it to use the Jakarta COMMONS-DBCP This package, also downloads the
COMMONS-DBCP the source of this package. Finally found the Getnumactive method in Basicdatasource, that's what I thought
Want.
Context Initctx = new InitialContext ();
Basicdatasource BDS = (basicdatasource) initctx.lookup ("Java:comp/env/jdbc/afunms");
Initctx.close ();
Bds.getconnection ();
SYSTEM.OUT.PRINTLN ("Current Connection number =" + bds.getnumactive ());
Any time getconnection () increases, the numactive also increases (if connection is not closed).
When numactive>maxactive (this maxactive is in an XML file), the program can no longer be connected to DB. It's
Is the reason why my previous program is wrong, haha.
Note: In the connection Pool profile. XML, specify
<parameter>
<name>factory</name>
<value> Org.apache.commons.dbcp.basicdatasourcefactory</value>
</parameter>