List:MySQL++« Previous MessageNext Message »
From:Jay Rajput Date:December 5 2008 9:37pm
Subject:How to get one Connection per thread
View as plain text  
Hi All,

How do I limit to one Connection per thread?

I am using the ConnectionPool class and I like it. But I would also like to
limit the number of grab and release in my thread to one. With the current
implementation I have a made a class whose constructor takes care of grabing
the Connection from the pool. The destructor takes care of releasing the
connection to the pool.

So if I have to make four queries in my thread, I have to grab the
connection four times and release it four times. I want to limit it to one.

What I would love to have is, when I enter my thread, if I need to query the
database, I should grab a connection. The same connection should then be
used for any other queries. Before giving my thread back to the pool, just
release the connection. The threads can also be used for non-database
operations so I just do not want to grab the connection for non-db
operations. This is something like thread specific singleton with a
singleton destruction when I am returning the thread to the pool.

I am using a thread pool, so the thread never exits they just go back to the
pool. I tried using ACE_TSS to make a thread specific singleton, but I am
not able to figure out how to release the connection. I am currenly only
able to grab it :-). I will be posting a question to the ACE community, but
I believe that the response on this list will be faster than any else.

Are there any example code which I can look for.

Thanks & Regards,

How to get one Connection per threadJay Rajput5 Dec
  • Re: How to get one Connection per threadWarren Young5 Dec