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

Пустовалов Дмитрий pustovalovdmit at gmail.com
Tue May 2 04:55:17 EDT 2017

Thanks, Boris!

Am I understand right that I should pass odb::database between the threads
and when I begin transaction on some thread passing to odb::transaction
return value from odb::database::begin I ensure that this transaction will
work on other database connection if needed?

пн, 1 мая 2017 г. в 19:34, Boris Kolpackov <boris at codesynthesis.com>:

> 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