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呢?

非常好。你的第一个问题已经在最新版本中更新了,这是原来的一个Bug;
2. getComponentNewInstance()是每次产生新的实例,TestServicePOJOImp类也将每次产生新的实例;jdbcDao是TestServicePOJOImp类的字段实例。

第一个问题:commonsPoolFactory时,为什么要先判断if (commonsPoolFactory == null)
这是一种lazy 初始化,应该一个targetDef对应一个commonsPoolFactory,所以更新版本中使用了map来装载。

谢谢.我刚才下了7月8日的框架版本,发现已经没有这个问题!!

zzcopy111 是有心人,如果发现任何问题请在这里指出,共同完善源码质量,这也是开源软件质量能够经得起考验的原因所在。