Spring object pooling woes
Spring's AOP support says that it includes object pooling. If you're using Spring and you have some object that is expensive to create, you can make a pool of some re-usable instances, and the documentation has an example of how to create a pool.
But according to my testing, the pool returns the same instance every time. Oops.
I found an old (2004) blog entry about this problem which included the a suggestion about making it work:
So, Spring object pooling appears broken, unless you know better...
But according to my testing, the pool returns the same instance every time. Oops.
I found an old (2004) blog entry about this problem which included the a suggestion about making it work:
<bean id="businessObject"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="targetSource" ref="poolTargetSource" />
<!-- Added the following line -->
<property name="singleton" value="false" />
</bean> This does indeed make the pool return different instances. But it doesn't explain how instances get returned to the pool. I was hoping that some Spring magic would occur to make this happen, but no. What seems to happen is that eventually the pool hands out an instance that has been used before, and it doesn't take many concurrent threads until your app gets into trouble because the same instance is used twice at once. Ouch.So, Spring object pooling appears broken, unless you know better...
