Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get pool information in java using BasicDataSource object  RSS feed

 
mohammad shadab
Ranch Hand
Posts: 54
Eclipse IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying to get the number of active connections using BasicDataSource object like following



Using above code , I am expecting following output



But always i do get zero as NumActive and NumIdle. Please suggest how can we get these .

Thanks
Shadab.
 
L Foster
Ranch Hand
Posts: 227
12
Android Angular Framework AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Mohammad:
You've introduced me to something I had not heard of prior.  Thanks for that.

I looked up the javadoc on this BasicDataSource object.  If I were trying to use this, I might first ask myself, "have I given proper parameters?"  To answer that, I would probe for other things even more obvious.  I would call "getUrl()", which you just set, and see if it matched, for instance.

Also, I would test my assumptions about what "idle" and "active" means.  I would do that by calling "getMaxActive()" and "getMaxIdle()".  Further, if that also gave me zero, I might wonder if I really need to get a connection to the datasource before any of this is reported.

One more thought: I have been using datasources supplied by servers for many years.  Usually that comes down to configuration with XML files or some such (on the filesystem used by the server, and housed in some deployment directory), and then in code either doing a JNDI lookup or injecting a factory of some kind.  Since I have seen that these settings have to be supplied somehow, I would be wondering if active and idle connections had to be configured prior to use.  I see that you have established a driver, URL and user/pass, but I do not see anything that dictates anything else about this data source.

HTH
 
mohammad shadab
Ranch Hand
Posts: 54
Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically i am using dbcp connection pooling , And in order to see the statistics of my app i want to know following parameters any point from the dbcp pool :-

1) Number of active connections
2) number of idle connections

Any idea will be great.

Thanks
Shadab.
 
Knute Snortum
Sheriff
Posts: 3553
86
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried any of the things L Foster suggested?  What happened when you did?
 
Jagadeeswar Hemadribhotla
Greenhorn
Posts: 2
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes we have tried suggestions given by foster. For total number and idle number, we are getting default number(8) where we configured total number to 10 in xml.
 
Knute Snortum
Sheriff
Posts: 3553
86
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What value do you get when you execute this in psql?

show max_connections;
 
Jagadeeswar Hemadribhotla
Greenhorn
Posts: 2
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting the following count as the max connections, however these figure relates to how many connections con be made to the DB but I am trying to get how many connections have been made from a specific web application context.

max_connections
-----------------
500
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!