Order Lock in C3p0

I am trying to register the creation and destruction of database connections in our application using c3p0 ConnectionCustomizer. In it, I have a code that looks like this:

log(C3P0Registry.getPooledDataSources())

I'm running to a dead end. I find that c3p0 has at least a few objects in its library that use synchronized methods and do not seem to indicate their intended blocking order. When I register connections, I hold the lock on C3P0Registryand end up PoolBackedDataSource(just creating a list of data sources allows you to access the hash code that causes the lock).

Shutting down the connection provider (call C3P0ConnectionProvider.close()) causes the locks to be called in the reverse order. But while the child data sources are closing, my log starts. The result is a dead end.

It seems that both the calls I make in the c3p0 library are valid, the expected calls are:

  • C3P0ConnectionProvider.close()
  • C3P0Registry.getPooledDataSources()

It also seems that (unless explicitly stated in the documentation), the responsibility for managing your own locking strategy should be in the library. (I'm not talking about this to blame anyone ... just to confirm my understanding of best practices)

How do I solve this problem? Since c3p0 uses synchronized methods and not a more modern mechanism, I cannot check for test locks.

DataSource C3P0Registry DataSource. , , .

, . C3P0Registry, DataSources, DataSources C3P0Registry, .

, , , c3p0. , , , .

. .

+5
1

, , , . " ..."

.

javax.sql.DataSource. . getConnection() , java.sql.Connection .. . , .

0

All Articles