0

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.

javastunt
  • 20
  • 6

1 Answers1

1

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.

ipolevoy
  • 5,432
  • 2
  • 31
  • 46
  • Thanks for the info! I'm using Jetty and so far it is doing quite well without further implementation of C3P0. I've thrown a lot of load test at it, and Jetty/Activeweb handles it 100%. – javastunt Aug 31 '16 at 14:53