• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting pool size in DBCP for connection pooling?

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to set the pool size for pooling data source.
here is what i am doing...



And this is how i retrieve connection



How can I set the poolsize? Is calling setMaxActive() setting the connection pool size?
Also, is it possible to increase the pool size dynamically or does dbcp automatically increases poolsize when it sees more incoming connection calls?

Giriraj.
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that setMaxActive will do the trick yes. I believe the pool grows from 1 to MaxSize as needed.
 
Giriraj Bhojak
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So if the connection pool is exhausted then will I be getting some exception or will DBCP do something about it?

Regards,
Giriraj.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the connection pool is exhausted, your application will wait indefinitely when it makes the request for the connection from pool.
Reference - http://commons.apache.org/dbcp/apidocs/org/apache/commons/dbcp/BasicDataSource.html#maxWait

This is very dangerous. Somebody may ask connection from the pool in the code and may not release it. In that case, you will see your application has hanged and there are no exception in logs.

Best thing to do is to set the maxWait property.

<property name="maxWait">
<value>60000</value>
</property>

Now, if a thread requests a connection and there is no free connection in the pool. application will throw - pool timeout exception after 1 minute ( as per config ). Once you can see the exception you can figure out something. If you application is using all the connection concurrently, you can increase the pool size a little bit. You can once again test it and if the pool size is again exhausted. There is high probability somewhere in the code connections are not released. You need to fix it.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic