You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by GF <ga...@gmail.com> on 2010/11/03 12:15:47 UTC

Discover the Datasource connection pool maxSize.

Hello.
i've not access to Tomcat's server.xml where the sysadmins defined a resource:

<Resource driverClassName="oracle.jdbc.driver.OracleDriver"
maxActive="65" maxIdle="30" maxWait="5" name="myDatasource"
type="javax.sql.DataSource" url="jdbc:....." />

I wish to discover from a web appplication deployed on that Tomcat
what's the configuration  "maxActive" for myDatasource.

Is there a way to discover it?
Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Discover the Datasource connection pool maxSize.

Posted by Rob Gregory <Ro...@ibsolutions.com>.
The following code fragment is used to auto create the datasource pool
and you can then use tds.getMaxWait etc. not sure if this is going to
help you with a tomcat specified connection pool but might give you some
pointers...



        DriverAdapterCPDS cpds = new DriverAdapterCPDS();
        ConnectionDetails objDetails = new
ConnectionDetails(datasource);
        
        try {
          cpds.setDriver(objDetails.getDriver()); //
"org.gjt.mm.mysql.Driver"
        } catch (ClassNotFoundException e) {
          log.error(e.getMessage());
          log.debug("StackTrace : ", e);
        }
        
        cpds.setUrl(objDetails.getUrl()); //
"jdbc:mysql://localhost:3306/bookstore"
        cpds.setUser(objDetails.getUsername());
        cpds.setPassword(objDetails.getPassword());
        
        SharedPoolDataSource tds = new SharedPoolDataSource();
        tds.setConnectionPoolDataSource(cpds);
        tds.setMaxActive(Config.getParamAsInt("pool.max.active"));  
        tds.setMaxWait(Config.getParamAsInt("pool.max.wait"));
        tds.setMaxIdle(Config.getParamAsInt("pool.max.idle"));
 
tds.setTestOnBorrow(Config.getParamAsBoolean("pool.test.on.borrow"));
 
tds.setTestOnReturn(Config.getParamAsBoolean("pool.test.on.return"));
 
tds.setTestWhileIdle(Config.getParamAsBoolean("pool.test.while.idle"));



> -----Original Message-----
> From: GF [mailto:ganfab@gmail.com]
> Sent: 03 November 2010 11:16
> To: Tomcat Users List
> Subject: Discover the Datasource connection pool maxSize.
> 
> Hello.
> i've not access to Tomcat's server.xml where the sysadmins defined a
resource:
> 
> <Resource driverClassName="oracle.jdbc.driver.OracleDriver"
> maxActive="65" maxIdle="30" maxWait="5" name="myDatasource"
> type="javax.sql.DataSource" url="jdbc:....." />
> 
> I wish to discover from a web appplication deployed on that Tomcat
> what's the configuration  "maxActive" for myDatasource.
> 
> Is there a way to discover it?
> Thank you.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Discover the Datasource connection pool maxSize.

Posted by Pid <pi...@pidster.com>.
On 03/11/2010 12:15, GF wrote:
> Hello.
> i've not access to Tomcat's server.xml where the sysadmins defined a resource:
> 
> <Resource driverClassName="oracle.jdbc.driver.OracleDriver"
> maxActive="65" maxIdle="30" maxWait="5" name="myDatasource"
> type="javax.sql.DataSource" url="jdbc:....." />
> 
> I wish to discover from a web appplication deployed on that Tomcat
> what's the configuration  "maxActive" for myDatasource.
> 
> Is there a way to discover it?
> Thank you.

JMX.  Connect a JMX client (JConsole) to your Tomcat instance and look
up the DataSource name & attributes.

 // check JMX names, something like:
 String dsName = "Catalina:type=DataSource,name=jdbc/DBName";
 String attrib = "maxActive";  // property name

 MBeanServerConnection mbsc =
   ManagementFactory.getPlatformMBeanServer();

 Set<ObjectName> names =
   mbsc.queryNames(ObjectName.getInstance(name), null);

 ObjectName ds = names.iterator.next();
 Integer maxActive = mbsc.getAttribute(ds, attrib);

YMMV


p

Re: Discover the Datasource connection pool maxSize.

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

GF,

On 11/3/2010 7:15 AM, GF wrote:
> i've not access to Tomcat's server.xml where the sysadmins defined a resource:
> 
> <Resource driverClassName="oracle.jdbc.driver.OracleDriver"
> maxActive="65" maxIdle="30" maxWait="5" name="myDatasource"
> type="javax.sql.DataSource" url="jdbc:....." />
> 
> I wish to discover from a web appplication deployed on that Tomcat
> what's the configuration  "maxActive" for myDatasource.

Try something like this:

import org.apache.tomcat.dbcp.dbcp.BasicDataSource;

...

DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/myDataSource");

if(ds instanceof BasicDataSource)
{
  BasicDataSource bds = (BasicDataSource)ds;

  maxActiveConnections = bds.getMaxActive();
  maxIdleConnections = bds.getMaxIdle();
  minIdleConnections = bds.getMinIdle();
  activeConnections = bds.getNumActive();
  idleConnections = bds.getNumIdle();
}

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkzRZ/AACgkQ9CaO5/Lv0PBZ9gCfZjFjk57HQJ0TkCX3DLJ7qwg0
xIwAnjlfrs9tNXk5URhrLYGHUzgSMTi/
=i8zY
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org