Current number of connections for the Tomcat connection pool

Source: Internet
Author: User

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>

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.