I would like to use Apache Pool 2 library, but looking for following functionality:
- The objects are not dummy new empty instances, but pre-loaded objects from external data source. You can imagine each object is unique working configuration which can be passed to generic task and such task will work. I don't need to clean up object, just return them.
- The number of objects in pool is fixed.
Isn't it better to write my own pool or is there way to achieve this with apache?
Or is there some better pattern to be used?
Ok, I followed the example on the site of Apache Pool and also investigated the documentation, but I really didn't find a way about how to push into pool my previously created object, so the only way I found work although really ugly was to: 1. Get dummy empty object from the pool in one loop and put them to external ArrayList 2. Loop over List and set objects and return those into the pool
After I try to obtain the object from the pool with following implementation those keep its setting which is behaviour as expected, but I would like to rather use factory to crate PooledObject which I can push somehow to pool. I tried use() of pool object, or wrap() method of genericobjectfactory, but it doesn't work as I expected it to work. So following code works as expected, sorry it is ugly as I just tested the functionality:
Here is log output where can be seen that again borrowed objects which were initially borrowed and configured are available:
So the behaviour is as expected, but I would simply extend the pool with put() method of the PooledObject as parameter, so you can initialize pool in more intuitive way...