6

I am working on multi threaded application(a server) where I used to handle 2000 clients at a time and I am opening separate database connection of MySQL database in each thread. So I have enabled the connection pooling. I searched on many blocks that after using connections we should close it then it will return back to pool and will be used by other thread. on the other hand we know that connection making is a time consuming process. So my question is why should we close connection in connection pooling. and what is better keep connection open or close them?

2 Answers 2

6

we know that connection making is a time consuming process

Correct - that's why we have connection pools. They maintain connections, so you don't create new ones.

why should we close connection in connection pooling

So they are returned to the pool to be used by other threads.

Connections are expensive resources, so you want to open, use and close them as quickly as possible, so they will return to the pool and be available to other threads.

Sign up to request clarification or add additional context in comments.

Comments

1

When you 'Close' a connection that is pooled;You are saying that you are done with the connection and the pool can use it again.

Calling Close does not physically tear down the connection. The pool has its own logic to determine when connections are physically closed.

1 Comment

Thanks Richard I was thinking that connection physically closed on closing them. but its not like that. Now I am clear about connection pooling :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.