Monday, June 21, 2010

Object Pool Pattern

Performance can be sometimes the key issue during the software development and the object creation (class instantiation) is a costly step. While the Prototype pattern helps in improving the performance by cloning the objects, the Object Pool pattern offers a mechanism to reuse objects that are expensive to create.

The Object Pool pattern offers mechanism to reuse/recycle objects that are expensive to create or are no longer need.

Object pool pattern is advisable to use in a situation where several client may need the same stateless object which is expensive to create.

Benefits of using Object Pool pattern are:

  • Pattern can improve performance of application as it help in reducing time for creation of expensive object.
  • Pattern helps in sharing unused object between multiple clients thereby improving memory usage and can result I overall reduction in memory footprint of application.
  • Additional memory management routine will not be required as resource user will acquire and release resource transparently.

The Consequences of this approach include:

  • In concurrent environment acquisition request for the resource needs t be synchronized in order to avoid race condition and possibility of corrupting associated state.
  • In case if resource users are involve in eager acquisition polling approach will fail.

No comments:

Post a Comment