Clearing JDBC Connection Pools

Does anyone know a better (or any) way to reset the JDBC connection pool? I cannot find anything obvious in the documentation. It looks like connection pools are not meant to be dropped.

My current thought is to remove all DataSources from the hash they are stored in, causing our code to create new ones. However, my first attempt is throwing a ConcurrentModificationException.

0
jdbc connection-pooling flush


source to share


3 answers


You shouldn't write a connection pool. Even if you want to manage the pool yourself (as opposed to letting the container do that), you must use a library to do this (like Commons DBCP).

If you want to remove everything from the hash, you must use hash.clear ().



If you want to avoid ConcurrentModificationException, you need to add sync.

If you are removing links to Connections (are you sure you mean DataSources?), Close them first ().

+1


source to share


Why would you want to delete and not create it first.



It should be based on your application server, maybe some JNDI programming could do the trick.

0


source to share


You shouldn't write a connection pool. This is handled by the Java EE Application Server.

0


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics