The object will batteries and other recreational pattern use for scenarios where creating objects is
expensive.
You can imagine an object billed as a library which checks in and out books whenever there is a demand
for the respective books.
Similarly, the pool will allocate a predefined number of objects and the client will use these objects
depending on its needs.
Some of the advantages of using object pools are objects are cached.
No need to create new objects all the time.
The client will ask for the pool for an object.
The client will ask the pool for an object and one of the cached objects will be returned.
The pattern also enforces object reusability.
Each time when a client does not need an object anymore, it will check out the respective object and
the pool will keep it for reusability purposes.
Some of the downsides of using object pools are.
They tend to be quite complex to implement, usually tread, he said, uncertain when using such a design
pattern and multi threading issues may occur if the implementation is not designed with safety in mind,
usually it requires other design patterns, which can lead to a more difficult to read object.
Polls are often created using the Singleton pattern to facilitate the same instance of the object will
throughout the program.
Also, factory pattern can also be used for creating new objects in the pool as well.
Last point is related to his popularity not being so used by the community due to its complexity.
You will find less articles and explanations on the Internet on how to implement it in Java, especially
if you compare this pattern with more popular operational ones such as factory and builder patterns.
Let's have a look in the code and see how it can be implemented.