5

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.

Martijn
  • 2,268
  • 3
  • 25
  • 51
  • I use this http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/jdbc.html but i'm really sure that activeJDBC is safe with multiple threads..I hope it helps. If you don't use datasource be careful with transactions and open/close connection. – ZaoTaoBao Apr 23 '14 at 14:54
  • How'd I go about implementing this with ActiveJDBC then? – Martijn Apr 23 '14 at 15:01
  • i only found an example, sure that you have seen https://github.com/florinpatrascu/micro-examples/tree/master/micro-aj explain min/max threads for jetty. srry. – ZaoTaoBao Apr 23 '14 at 15:26

1 Answers1

4

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

ipolevoy
  • 5,432
  • 2
  • 31
  • 46