Matt
Matt

Reputation:

Flushing JDBC connection pools

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.

Upvotes: 1

Views: 3803

Answers (3)

Thilo
Thilo

Reputation: 262774

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.

Upvotes: 1

duffymo
duffymo

Reputation: 308988

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

Upvotes: 0

Mohan Narayanaswamy
Mohan Narayanaswamy

Reputation: 2149

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.

Upvotes: 0

Related Questions