You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ashish Kulkarni <as...@gmail.com> on 2010/07/09 21:03:57 UTC

tomcat datasource, find active connections

Hi
I have following in context.xml, and it works fine.
But i would like to find how many active connections are there in data
source or how many total connections are there?
1 is it possible to do so?

2 Can i change type javax.sql.DataSource
to com.ibm.as400.access.AS400JDBCDataSource, as this has methods to find
active connections etc?

<Resource name="jdbc/mydev"  auth="Container"
 type="javax.sql.DataSource"
                  maxActive="2"
                  maxIdle="2"
                  maxWait="3000"
                  username="user"
                  password="pass"
                  driverClassName="com.ibm.as400.access.AS400JDBCDriver"
                  url="jdbc:as400://1mysystem;date format=iso;time
format=iso;errors=basic;trace=false;"
                  validationQuery="select * from   mytable" />


-- 
Ashish
www.ayurwellness.com
www.mysoftwareneeds.com

Re: tomcat datasource, find active connections

Posted by David kerber <dc...@verizon.net>.
On 7/12/2010 11:23 AM, Ken Bowen wrote:
> Perhaps  " select 1"  is the simplest & lightest weight.

If the db will accept it (without a FROM clause), yes.

D

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


Re: tomcat datasource, find active connections

Posted by Ken Bowen <kb...@als.com>.
Perhaps   " select 1"    is the simplest & lightest weight.

On Jul 12, 2010, at 11:04 AM, David kerber wrote:

> On 7/12/2010 10:50 AM, Pid wrote:
>> On 12/07/2010 15:15, Ashish Kulkarni wrote:
>>> Hi
>>> Where do i specify data source factory? i have following setup
>>>
>>> <Resource name="jdbc/mydev"
>>>    auth="Container"
>>>                  type="javax.sql.DataSource"
>>>                  maxActive="2"
>>>                  maxIdle="2"
>>>                  maxWait="3000"
>>>                  username="user"
>>>                  password="password"
>>>                   
>>> driverClassName="com.ibm.as400.access.AS400JDBCDriver"
>>>                  url="jdbc:as400://myip;date format=iso;time
>>> format=iso;errors=basic;trace=false;"
>>>                   validationQuery="select * from    
>>> myschema.mytable" />
>>
>> Is that the most lightweight validation query you can use?
>
> Yeah, you might add a "WHERE true = false" to it, so you don't make  
> the db actually do any work.
>
> D
>
> ---------------------------------------------------------------------
> 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: tomcat datasource, find active connections

Posted by David kerber <dc...@verizon.net>.
On 7/12/2010 10:50 AM, Pid wrote:
> On 12/07/2010 15:15, Ashish Kulkarni wrote:
>> Hi
>> Where do i specify data source factory? i have following setup
>>
>> <Resource name="jdbc/mydev"
>>     auth="Container"
>>                   type="javax.sql.DataSource"
>>                   maxActive="2"
>>                   maxIdle="2"
>>                   maxWait="3000"
>>                   username="user"
>>                   password="password"
>>                   driverClassName="com.ibm.as400.access.AS400JDBCDriver"
>>                   url="jdbc:as400://myip;date format=iso;time
>> format=iso;errors=basic;trace=false;"
>>                    validationQuery="select * from   myschema.mytable" />
>
> Is that the most lightweight validation query you can use?

Yeah, you might add a "WHERE true = false" to it, so you don't make the 
db actually do any work.

D

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


Re: tomcat datasource, find active connections

Posted by Pid <pi...@pidster.com>.
On 12/07/2010 15:15, Ashish Kulkarni wrote:
> Hi
> Where do i specify data source factory? i have following setup
> 
> <Resource name="jdbc/mydev"
>    auth="Container"
>                  type="javax.sql.DataSource"
>                  maxActive="2" 
>                  maxIdle="2" 
>                  maxWait="3000"
>                  username="user" 
>                  password="password"
>                  driverClassName="com.ibm.as400.access.AS400JDBCDriver"
>                  url="jdbc:as400://myip;date format=iso;time
> format=iso;errors=basic;trace=false;"
>                   validationQuery="select * from   myschema.mytable" />

Is that the most lightweight validation query you can use?


You need to add the 'factory="..."' element.  It's default value is:

 'org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory'

N.B. the double dbcp.dbcp is intentional.
There's more documentation about configuring a DataSource here:

 http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html#Database_Connection_Pool_(DBCP)_Configurations

 http://wiki.apache.org/commons/DBCP


You will need to determine whether there is a suitable DataSource
factory class, in the com.ibm.as400.access package, or write your own
wrapper.  A quick Google search indicates someone else has done this
(AS400JDBCDataSourceFactory)


p


> On Fri, Jul 9, 2010 at 5:42 PM, Pid <pid@pidster.com
> <ma...@pidster.com>> wrote:
> 
>     On 09/07/2010 20:03, Ashish Kulkarni wrote:
>     > Hi
>     > I have following in context.xml, and it works fine.
>     > But i would like to find how many active connections are there in data
>     > source or how many total connections are there?
>     > 1 is it possible to do so?
>     >
>     > 2 Can i change type javax.sql.DataSource
>     > to com.ibm.as400.access.AS400JDBCDataSource, as this has methods
>     to find
>     > active connections etc?
> 
>     Nope.
> 
>     If you use an appropriate DataSourceFactory that creates a
>     AS400JDBCDataSource then you can cast the DataSource that results from
>     the calls to JNDI to the one you want.
> 
>     Or you can use JMX to examine the running Tomcat.
> 
> 
>     p
> 
>     > <Resource name="jdbc/mydev"  auth="Container"
>     >  type="javax.sql.DataSource"
>     >                   maxActive="2"
>     >                   maxIdle="2"
>     >                   maxWait="3000"
>     >                   username="user"
>     >                   password="pass"
>     >                  
>     driverClassName="com.ibm.as400.access.AS400JDBCDriver"
>     >                   url="jdbc:as400://1mysystem;date format=iso;time
>     > format=iso;errors=basic;trace=false;"
>     >                   validationQuery="select * from   mytable" />
>     >
>     >
> 
> 
> 
> 
> 
> -- 
> Ashish
> www.ayurwellness.com <http://www.ayurwellness.com>
> www.mysoftwareneeds.com <http://www.mysoftwareneeds.com>



Re: tomcat datasource, find active connections

Posted by Konstantin Kolinko <kn...@gmail.com>.
2010/7/14 Caldarale, Charles R <Ch...@unisys.com>:
>> From: Christopher Schultz [mailto:chris@christopherschultz.net]
>> Subject: Re: tomcat datasource, find active connections
>>
>> As much fun as that sounds, the OP could just use the default
>> DataSourceFactory which is based upon DBCP.
>
> Does that require setting the <Context> privileged attribute to true in 5.5?  (Looks like it shouldn't make a difference in 6.0 and 7.0.)
>

naming-factory-dbcp.jar is in common/lib/ in TC 5.5, so setting
privileged=true is not needed, I think.  privileged is used to get
access to jars that are in server/lib


Best regards,
Konstantin Kolinko

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


RE: tomcat datasource, find active connections

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Subject: Re: tomcat datasource, find active connections
> 
> As much fun as that sounds, the OP could just use the default
> DataSourceFactory which is based upon DBCP.

Does that require setting the <Context> privileged attribute to true in 5.5?  (Looks like it shouldn't make a difference in 6.0 and 7.0.)

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.



Re: tomcat datasource, find active connections

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

Chuck,

On 7/12/2010 10:38 AM, Caldarale, Charles R wrote:
>> From: Ashish Kulkarni [mailto:ashish.kulkarni13@gmail.com]
>> Sent: 2010 July 12, Monday 09:16
>> To: Tomcat Users List; pid@pidster.com
>> Subject: Re: tomcat datasource, find active connections
>>
>> Where do i specify data source factory?
> 
> http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#Adding_Custom_Resource_Factories

As much fun as that sounds, the OP could just use the default
DataSourceFactory which is based upon DBCP. We use the following in a
"health check" JSP we have.

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

        Context ctx = new InitialContext();

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

        if(null == ds)
                throw new NamingException("Cannot obtain DataSource");

        int maxActiveConnections = 0;
        int maxIdleConnections = 0;
        int minIdleConnections = 0;
        int activeConnections = 0;
        int idleConnections = 0;

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

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

Feel free to add more types of DataSource to fetch their counters.

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

iEYEARECAAYFAkw9MvkACgkQ9CaO5/Lv0PAoUwCffLW2kYhnQY/1uYP+NcrQDvjy
GIgAnRa/VgcfHBm114eW5LgxlJBTmv7I
=QwO9
-----END PGP SIGNATURE-----

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


RE: tomcat datasource, find active connections

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Ashish Kulkarni [mailto:ashish.kulkarni13@gmail.com]
> Sent: 2010 July 12, Monday 09:16
> To: Tomcat Users List; pid@pidster.com
> Subject: Re: tomcat datasource, find active connections
> 
> Where do i specify data source factory?

http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#Adding_Custom_Resource_Factories

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


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


Re: tomcat datasource, find active connections

Posted by Ashish Kulkarni <as...@gmail.com>.
Hi
Where do i specify data source factory? i have following setup

<Resource name="jdbc/mydev"
     auth="Container"
                  type="javax.sql.DataSource"
                  maxActive="2"
                  maxIdle="2"
                  maxWait="3000"
                  username="user"
                  password="password"
                  driverClassName="com.ibm.as400.access.AS400JDBCDriver"
                  url="jdbc:as400://myip;date format=iso;time
format=iso;errors=basic;trace=false;"
                  validationQuery="select * from   myschema.mytable" />



On Fri, Jul 9, 2010 at 5:42 PM, Pid <pi...@pidster.com> wrote:

> On 09/07/2010 20:03, Ashish Kulkarni wrote:
> > Hi
> > I have following in context.xml, and it works fine.
> > But i would like to find how many active connections are there in data
> > source or how many total connections are there?
> > 1 is it possible to do so?
> >
> > 2 Can i change type javax.sql.DataSource
> > to com.ibm.as400.access.AS400JDBCDataSource, as this has methods to find
> > active connections etc?
>
> Nope.
>
> If you use an appropriate DataSourceFactory that creates a
> AS400JDBCDataSource then you can cast the DataSource that results from
> the calls to JNDI to the one you want.
>
> Or you can use JMX to examine the running Tomcat.
>
>
> p
>
> > <Resource name="jdbc/mydev"  auth="Container"
> >  type="javax.sql.DataSource"
> >                   maxActive="2"
> >                   maxIdle="2"
> >                   maxWait="3000"
> >                   username="user"
> >                   password="pass"
> >                   driverClassName="com.ibm.as400.access.AS400JDBCDriver"
> >                   url="jdbc:as400://1mysystem;date format=iso;time
> > format=iso;errors=basic;trace=false;"
> >                   validationQuery="select * from   mytable" />
> >
> >
>
>
>


-- 
Ashish
www.ayurwellness.com
www.mysoftwareneeds.com

Re: tomcat datasource, find active connections

Posted by Pid <pi...@pidster.com>.
On 09/07/2010 20:03, Ashish Kulkarni wrote:
> Hi
> I have following in context.xml, and it works fine.
> But i would like to find how many active connections are there in data
> source or how many total connections are there?
> 1 is it possible to do so?
> 
> 2 Can i change type javax.sql.DataSource
> to com.ibm.as400.access.AS400JDBCDataSource, as this has methods to find
> active connections etc?

Nope.

If you use an appropriate DataSourceFactory that creates a
AS400JDBCDataSource then you can cast the DataSource that results from
the calls to JNDI to the one you want.

Or you can use JMX to examine the running Tomcat.


p

> <Resource name="jdbc/mydev"  auth="Container"
>  type="javax.sql.DataSource"
>                   maxActive="2"
>                   maxIdle="2"
>                   maxWait="3000"
>                   username="user"
>                   password="pass"
>                   driverClassName="com.ibm.as400.access.AS400JDBCDriver"
>                   url="jdbc:as400://1mysystem;date format=iso;time
> format=iso;errors=basic;trace=false;"
>                   validationQuery="select * from   mytable" />
> 
>