I have a question.
Can I share opened connections in connection pool between tasks?
One task locks connection from pool, uses it and returns opened connection back to pool. Is it possible another task to lock already opened connection and to use it?
For example, reusing connections to MySQL server without extra open/close operations.
Am 25.07.2013 13:57, schrieb Jack Applegame:
I have a question.
Can I share opened connections in connection pool between tasks?
One task locks connection from pool, uses it and returns opened connection back to pool. Is it possible another task to lock already opened connection and to use it?
For example, reusing connections to MySQL server without extra open/close operations.
Yes, ConnectionPool
does this. Any call to lockConnection
will first
check if there is any unused connection and only create a new one if
not. The LockedConnection
proxy makes sure that only a single task can
access the same connection at a time.
It is not thread-safe, though, so it doesn't share a connection between
different threads (or, rather, the ConnectionPool
itself is not
supposed to be shared between threads).
It is not thread-safe, though, so it doesn't share a connection between
different threads (or, rather, theConnectionPool
itself is not
supposed to be shared between threads).
I think, this can be solved by creating in TLS own pool for every thread.
Am 25.07.2013 14:55, schrieb Jack Applegame:
It is not thread-safe, though, so it doesn't share a connection between
different threads (or, rather, theConnectionPool
itself is not
supposed to be shared between threads).
I think, this can be solved by creating in TLS own pool for every thread.
Exactly. This is done for example in the HTTP client (connectHTTP
).