Introducing connection pooling for Habari Client libraries

Habarisoft introduces dynamic connection pooling with the next release of its message broker client libraries for Delphi and Free Pascal. Connection pools save resources in multi-threaded applications, as connections are initialized only once and then shared between threads. They can speed up the program execution because the pool returns and stored them in started state.

The key parts of thread-safe connection pooling with Habari libraries are the classes TBTConnectionPool and TPoolableConnectionFactory. The connection pool class provides two methods:

  • BorrowConnection – this method returns a started IConnection instance
  • ReturnConnection – this method returns the instance back to the pool

These two methods are best used with a tryfinally block to ensure that the connection will be returned to the pool:

  Conn := Pool.BorrowConnection;
  ... use the connection

Creating a connection pool

Creating the pool is easy and requires only one line of code. After instantiating the poolable connection factory

Factory := TBTPoolableConnectionFactory.Create(...);

the pool can be created with this factory, an initial pool size, and dynamic sizing with this line of code:

Pool := TBTConnectionPool.Create(Factory, 2, eaGrow);


This early implementation has some limitations, but all registered users of Habari Client libraries can receive the source code to try it and to give feedback.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s