javastunt
javastunt

Reputation: 20

Activeweb/ActiveJDBC with C3P0 database connections

I'm attempting to get an ActiveWeb/ActiveJDBC connection configured to use C3P0 for connection pooling.

I know the documentation provided by Javalite says each transaction will be a single opened/closed connection, but does also mentions we can open a datasource via:

new DB("default").open( cpds );

This leads me to think it might be possible to intercept the connection open/close mechanism by including on AppControllerConfig:

addGlobalFilters( new DBConnectionFilterTest("default", true)  );

... where DBConnectionFilterTest is a custom class extending DBConnectionFilter that overrides the before/after behavior that opens and closes the connection. The Datasource is configured within the constructor using a ComboPooledDataSource.

I was curious if anyone had any insight on this configuration, or have been successful in integrating C3P0 to activeweb/activeJDBC?

The furthest I have gotten so far is to get C3P0 to fire up. I see the 5 connections in my session monitor, but activeweb still initiates a new connection when performing a transaction. The C3P0 pool hasn't moved.

Upvotes: 0

Views: 206

Answers (1)

ipolevoy
ipolevoy

Reputation: 5518

Since you are writing your own filter to open and close a connection, do not forget to close a connection after a request is completed. This will return the connection back to the pool. Check out DBConnectionFilter code, specifically methods onException() and after(). If for some reason you will not close a connection, ActiveWeb will attempt to close it for you, but will complain in the log.

Personally, I use a built-in pool from Tomcat. It performs without any issues in production environments under a heavy load. A standard implementation of DBConnectionFilter does it then.

Upvotes: 1

Related Questions