views:

473

answers:

3

Does anyone know the best (or any) way to flush a JDBC connection pool? I can't find anything obvious in the documentation. It appears connection pools aren't meant to ever be deleted.

My current thought is to delete all DataSources from the hash we store them in, which will trigger our code to make new ones. However, my first attempt throws a ConcurrentModificationException.

A: 

Why do you want to delete, rather don't create it at first place.

It should be based on your appserver, may be some JNDI programming could do the trick.

A: 

You shouldn't be writing a connection pool. That's handled by the Java EE app server.

duffymo
A: 

You shouldn't be writing a connection pool. Even if you want to manage the pool yourself (as opposed to letting a container do it), you should use a library for that (such as Commons DBCP).

If you want to delete everything from a hash, you should use hash.clear().

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

If you delete references to Connections (are you sure you meant DataSources?), be sure to close() them first.

Thilo