I have Spring CommonsPoolTargetSourcedefined for bean. I am trying to understand how pooling works and when an object returns to a pool.
In particular, if I have a worker who takes the combined object and calls two methods on it:
public class MyWorker {
@Resource
Foo pooledFoo;
void doWork()
{
pooledFoo.doStepA();
pooledFoo.doStepB();
}
}
From what I see in the tests I ran, it pooledFoo’s not really an instance Foo, but a proxy provided by the pool. The stream in the above form will be as follows:
- The doStepA () on call
Fooretrieves the value from the pool (blocking the thread if it is not available), - doStepA is executed in the pooledFoo file
- When doStepA is complete, the instance
pooledFooreturns to the pool - the control returns to the method
doWorkand the method continues
(, , ), , pooledFoo, doStepB(), , doStepA()