[odb-users] safe usage odb connection pool in multi threaded environment (odb 2.4.0)

Boris Kolpackov boris at codesynthesis.com
Mon May 1 12:34:36 EDT 2017


Hi,

Пустовалов Дмитрий <pustovalovdmit at gmail.com> writes:

> I want to figure out a proper way to manage database connection pool
> assuming I want to use connection in different threads.

You are over-thinking and over-complicating things ;-). ODB database
is a thread-safe connection pool. So just pass a single instance of the
database to all your threads and execute your database operations
on it. All the connection management will be taken care of in a
thread-safe manner.

If you do want to work with connections explicitly for some reason
(for example you want to make sure two transactions are executed
on the same connection), then keep them local to the same thread.
That is, get it in the thread, use for as long as necessary, then
release in the same thread.

Boris



More information about the odb-users mailing list