**Last Update**: 26.11.2023
***
### What Is Object Pool Pattern?
- The Object Pool Pattern is a software creational design pattern that uses a set of initialized objects, or an "object pool", kept ready to use rather than allocating and deallocating them on the fly.
- When an object is taken from the pool, it is not available in the pool until it's returned.
- Objects in the pool have a lifecycle: creation, validation, and destruction. Here's how it typically operates:
1. When the client asks for an object, the pool first attempts to provide one of its free ones.
2. If there are no objects ready and the pool isn't full yet, it creates a new one.
3. If all objects are busy and the pool can't create new ones, it waits until some objects are returned.
4. The client must return every object it has taken once it's done using it.
5. The pool validates all incoming objects and properly destroys those that are invalid.
### When Is Object Pool Pattern used?
- This pattern is used in scenarios where object initialization is expensive and could significantly impact performance.
- Object pools can improve application performance in situations where the cost of initializing a class instance is high, the rate of instantiation of a class is high, and the number of instances in use at any one time is low.
### What object-pooling libraries are available?
[**Apache Commons Pool**](https://commons.apache.org/proper/commons-pool/):
- This is a robust, generic, highly configurable object-pooling library from Apache. You can pool any object using this library.
- It provides great flexibility by allowing you to configure parameters like max total instances to keep in the pool, max idle instances, min idle instances, max active instances and others.
You can a find a *Selenium WebDriver* object pooling example implemented with *Java* and *Apache Commons Pool* [here](https://github.com/ehayik/web-scraping-kata/tree/master/src/main/java/org/github/ehayik/kata/webscraping/infrastructure/webdriver/pool)