Search code examples
javamysqlmultithreadingactivejdbc

Using ActiveJDBC with multiple threads


I have an application that is built on ActiveJDBC for Database interactions. I'm now in the process of multithreading the thing but I'm running into a couple issues.

Whenever I try to get an object from the DB, I get this exception: Cannot open a new connection because existing connection is still on current thread, dbName: default, connection instance: com.mchange.v2.c3p0.impl.NewProxyConnection@75412c2f. This might indicate a logical error in your application.

Note it says com.mchange.v2.c3p0.impl.NewProxyConnection. This is so because I already tried to use DataSources but that didn't either. Could somebody point me to the track or suggest an alternative (threadsafe) to Active JDBC?

Thanks.


Solution

  • The error message you are getting is quite explanatory. Connection was not closed. ActiveJDBC is certainly thread-safe, as we built quite a number of projects with it. However ActiveJDBC attaches a connection to a current thread with Base.open() method and removes it from this thread using Base.close() method. I think you are forgetting to do the latter. Please see this to understand more: http://javalite.io/database_connection_management