benq,你好!框架中有关 池的使用问题请教一下
请问两下问题:
(1)实现对象池拦截的类PoolInterceptor里
有这么一段代码.
if (commonsPoolFactory == null) {
commonsPoolFactory = getCommonsPoolFactory(targetMetaDef);
}
Pool pool = commonsPoolFactory.getPool();
Object poa = null;
Object result = null;
try {
poa = pool.acquirePoolable();
Debug.logVerbose(" borrow a object:" + targetMetaDef.getClassName()
+ " from pool", module);
//set the object that borrowed from pool to MethodInvocation
//so later other Interceptors or MethodInvocation can use it!
proxyMethodInvocation.setThis(poa);
result = invocation.proceed();
} catch (Exception ex) {
Debug.logError(ex, module);
} finally {
if (poa != null) {
pool.releasePoolable(poa);
Debug.logVerbose(" realease a object:" + targetMetaDef.getClassName()
+ " to pool", module);
}
}
有点不太明白,在取commonsPoolFactory时,为什么要先判断if (commonsPoolFactory == null)
是否为空.PoolInterceptor是个在PicoContainerWrapper中已经注册的一个单例类.
commonsPoolFactory又是在PoolInterceptor类中的一个类变量.
这样要执行另外一个POJO的targetMetaDef时,就不会在调用getCommonsPoolFactory(targetMetaDef),
产生一个新的工厂了.那么下面 Pool pool = commonsPoolFactory.getPool();再得到的池不就不批配了嘛.
(2) PicoContainerWrapper类中的getComponentNewInstance()方法,会不会使picoContainer中产生多个相同的对象.
如果产生的话,那么他们的依赖的对象是不是也会产生多个.
也是说如果产生两个TestServicePOJOImp会不会也产生两个JdbcDAO呢?