English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

1 answers

Here's a simple pooling algorithm you can use:

1) Create a stack (abstract data type -- java.util.Stack if you're using Java)

2) Open a handful of connections to the database or server for which you're pooling connections. Push them onto the stack.

3) If someone requests a connection, pop one off the stack and give it to them.

3a) If you underflowed the stack (i.e. there isn't one on the stack to give them), create another handful of connections, push them onto the stack, then pop one off the stack & return it.

4) When somebody's done with a connection, the code needs to return it to the pool. Pop the connection back onto the stack so it's there the next time someone needs it.

2006-11-16 16:22:33 · answer #1 · answered by watsonc64 3 · 0 0

fedest.com, questions and answers