Thread: Re: [cx-oracle-users] is SessionPool thread safe?
Brought to you by:
atuining
From: Forest W. <mo...@ti...> - 2005-09-15 16:59:52
|
Thanks for the response, but I'm afraid it doesn't explain the matter. It tells me how Connection objects behave when shared among threads, but it does not tell me how SessionPool objects behave when shared among threads. One interpretation of what you wrote (and of the documentation) is that SessionPool.acquire() returns a thread-safe object when it was constructed with threaded=True, but the SessionPool.acquire() call itself is not thread safe. If that is the case, a program's main thread could safely acquire() Connections and then pass them to worker threads, but multiple worker threads could not safely call acquire() on their own. My program's worker threads have to acquire() Connections on an as-needed basis, rather than being handed a Connection when they start up. The answer to my question will determine whether I have to write my own synchronization wrapper for SessionPool.acquire(). Anthony Tuininga <ant...@gm...> wrote: > If you specify "threaded =3D True" in the constructor of the session > pool, Oracle guarantees thread safety provided you use one thread for > each connection you use. If you want more than one thread to access a > connection, you will have to synchronize access. Does that explain the > matter sufficiently? > > On 9/12/05, Forest Wilkinson <mo...@ti...> wrote: > >>I'm using cx_Oracle SessionPool objects in a threaded http server. Since >>I didn't see an explicit statement in the docs that SessionPool.acquire() >>and SessionPool.release() are thread safe, I'm currently synchronizing >>access to those methods with a threading.Condition object. Is this >>necessary? If SessionPool does its own method synchronization, I'll get >>rid of my wrapper class and perhaps get better performance. >>=20 >>=20 |
From: Forest W. <mo...@ti...> - 2005-09-16 16:23:13
|
Yes, I understand now, thanks. Too bad Oracle's docs aren't more explicit. :) Anthony Tuininga <ant...@gm...> wrote: > Ok, I'll try again. :-) As far as I know the session pool acquire > method is thread safe. There is no Oracle documentation that says > otherwise and the description of OCI_THREADED mode seems to imply that > it is thread safe. We have also done precisely what you are doing > (acquiring a connection from a pool in a worker thread) in our own > product and have never run into a problem. If we forget to set > "threaded =3D True" in the session pool constructor, though, all kinds > of trouble occurs. :-) Does that answer your question sufficiently > now? |
From: Anthony T. <ant...@gm...> - 2005-09-15 17:10:50
|
Ok, I'll try again. :-) As far as I know the session pool acquire method is thread safe. There is no Oracle documentation that says otherwise and the description of OCI_THREADED mode seems to imply that it is thread safe. We have also done precisely what you are doing (acquiring a connection from a pool in a worker thread) in our own product and have never run into a problem. If we forget to set "threaded =3D True" in the session pool constructor, though, all kinds of trouble occurs. :-) Does that answer your question sufficiently now? On 9/15/05, Forest Wilkinson <mo...@ti...> wrote: > Thanks for the response, but I'm afraid it doesn't explain the matter. I= t > tells me how Connection objects behave when shared among threads, but it > does not tell me how SessionPool objects behave when shared among threads= . >=20 > One interpretation of what you wrote (and of the documentation) is that > SessionPool.acquire() returns a thread-safe object when it was constructe= d > with threaded=3DTrue, but the SessionPool.acquire() call itself is not > thread safe. If that is the case, a program's main thread could safely > acquire() Connections and then pass them to worker threads, but multiple > worker threads could not safely call acquire() on their own. >=20 > My program's worker threads have to acquire() Connections on an as-needed > basis, rather than being handed a Connection when they start up. The > answer to my question will determine whether I have to write my own > synchronization wrapper for SessionPool.acquire(). >=20 > Anthony Tuininga <ant...@gm...> wrote: >=20 > > If you specify "threaded =3D3D True" in the constructor of the session > > pool, Oracle guarantees thread safety provided you use one thread for > > each connection you use. If you want more than one thread to access a > > connection, you will have to synchronize access. Does that explain the > > matter sufficiently? > > > > On 9/12/05, Forest Wilkinson <mo...@ti...> wrote: > > > >>I'm using cx_Oracle SessionPool objects in a threaded http server. Sin= ce > >>I didn't see an explicit statement in the docs that SessionPool.acquire= () > >>and SessionPool.release() are thread safe, I'm currently synchronizing > >>access to those methods with a threading.Condition object. Is this > >>necessary? If SessionPool does its own method synchronization, I'll ge= t > >>rid of my wrapper class and perhaps get better performance. > >>=3D20 > >>=3D20 >=20 >=20 >=20 > ------------------------------------------------------- > SF.Net email is sponsored by: > Tame your development challenges with Apache's Geronimo App Server. Downl= oad > it for free - -and be entered to win a 42" plasma tv or your very own > Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > |