Problem with recycling connection pool

Hi Group,

I am using DBCP provided connection pool in my web applications. For each re-deployment of my web application, connection pools are not reused so connections are just increased. This forces me to restart my live application in every month. Is there any way, I can reuse connections in redeploy.

Your help would be appreciated.

regards,

Ranjan

Edit/Delete Message

Message was edited by:

ranjanbaisak

[458 byte] By [ranjanbaisaka] at [2007-11-27 5:09:31]
# 1

This is not a JDBC problem. It's a classloading issue. You might have more luck in a J2EE forum. I've had the same kind of problem in the past. We had to restart the app server on each deployment. Whether there is another solution depends on what software your app is hosted on. You might want to also consider clustering your app so you can restart the server without an outage.

dubwaia at 2007-7-12 10:29:16 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

You might be correct.

I also tried to implemen preProcess/init/destroy method of struts RequestProcessor. However it is some how *NOT WORKING*.

May be there are some advanced configuration setting needed in DBCP to fix this. ANybody more familiar with DBCP can throw some idea.

Somebody suggested me to use autoReconnect=true in url pattern of DBCP configuration and I also tried that still connections are getting increased in DB server.

This is more related to recycling all unused db connection or closing all unused db connections.

Something like connection pool should try to get all unused db connections and reuse them before requesting for a fresh db connection to db server, and if there are no unused connections then pool should request for new db connections which is not happening in my case. Each time I redeploy, pool makes a fresh db connection with server.

Let me try with some DBCP forums.

ranjanbaisaka at 2007-7-12 10:29:16 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

> This is more related to recycling all unused db

> connection or closing all unused db connections.

> Something like connection pool should try to get all

> unused db connections and reuse them before

> requesting for a fresh db connection to db server,

> and if there are no unused connections then pool

> should request for new db connections which is not

> happening in my case. Each time I redeploy, pool

> makes a fresh db connection with server.

When you redeploy, you are creating a new pool. It doesn't know about the existing pool(s) and doesn't have any access to their connections. That is at least the problem I have seen in the past. You can bang on the new pool instance all you want, it will never clear the old pool's connections. In a nutshell, your new deployment basically creates all new classes as far as the JVM is concerned. The new pool's class is not the same as the old pool's class. You can verify whether this is the case by writing this out to your logging:

"pool class identity" + System.identityHashCode(poolInstance.getClass())

If what I am suggesting is correct, you should see a different value on each deployment.

dubwaia at 2007-7-12 10:29:16 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

Yes you are correct.

I must admit that it would be very difficult for me to restart web application nor can I make it clustered.

In other way, I tried to implement destroy method of RequestProcessor which gets invoked while I redeploy my web application and performed datasource.close(); which in turn should close all the connections.

And it is not working. Any reason why this should not work.

ranjanbaisaka at 2007-7-12 10:29:16 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

> Yes you are correct.

> I must admit that it would be very difficult for me

> to restart web application nor can I make it

> clustered.

> In other way, I tried to implement destroy method of

> RequestProcessor which gets invoked while I redeploy

> my web application and performed datasource.close();

> which in turn should close all the connections.

> And it is not working. Any reason why this should not

> work.

So just to be clear, you are doing this before redeploying the new classes right?

If you are calling this on the DataSource, returned by the pool, it's jut going to return the connection to the pool. You need a way to tell the pool to close it's connections and stop retrieving more. This is all going to depend on the pool implementation and whether it provides this facility. If it does not, you need to contact the vendor or consider other pool implementations that provide this feature.

dubwaia at 2007-7-12 10:29:16 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
>So just to be clear, you are doing this before redeploying the new classes right?Yes it happens before redeploying new classes. RequestProcessor is a struts API and used by ActionServlet to process request by container.
ranjanbaisaka at 2007-7-12 10:29:16 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7

I somehow managed to clear/close all physical connections in each redeployment of my application.

I made following changes to close all connections of datasource object

1) Changed javax.sql.DataSource to org.apache.commons.dbcp.BasicDataSource. javax.sql.DataSource does not have any close() method that closes all connections and close() method BasicDataSource says that

"Close and release all connections that are currently stored in the connection pool associated with our data source."

2) Implemented destroy method in RequestProcessor class and called BasicDataSource.close() method to close and release all connections.

This works correctly. Any input why this should not work?

ranjanbaisaka at 2007-7-12 10:29:16 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8

> This works correctly. Any input why this should not

> work?

I think this is basically what I suggested, is it not? You looked into the specifics of the pool and found a method that allows you to close the actual connections to the database.

The only issue is that if you use another pool vendor, this will almost surely throw a ClassCastException.

dubwaia at 2007-7-12 10:29:16 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...