Spring integration spring集成CachingSessionFactory会话池澄清

Spring integration spring集成CachingSessionFactory会话池澄清,spring-integration,Spring Integration,我们正在使用spring集成CachingSessionFactory来缓存sftp会话。所有这些都可以正常工作,但有一个问题是如何处理这些会话 例如,如果我的池大小为10,并且如果其中一个会话已过时(可能已断开与实际sftp服务器的连接),那么在使用之前是否会抛出该陈旧会话并替换为另一个良好会话。是的,您的结论是正确的CachingSessionFactory基于org.springframework.integration.util.SimplePool,请求的代码如下所示: private

我们正在使用spring集成CachingSessionFactory来缓存sftp会话。所有这些都可以正常工作,但有一个问题是如何处理这些会话


例如,如果我的池大小为10,并且如果其中一个会话已过时(可能已断开与实际sftp服务器的连接),那么在使用之前是否会抛出该陈旧会话并替换为另一个良好会话。

是的,您的结论是正确的
CachingSessionFactory
基于
org.springframework.integration.util.SimplePool
,请求的代码如下所示:

private T doGetItem() {
    T item = this.available.poll();
    if (item != null && logger.isDebugEnabled()) {
        logger.debug("Obtained " + item + " from pool.");
    }
    if (item == null) {
        item = this.callback.createForPool();
        if (logger.isDebugEnabled()) {
            logger.debug("Obtained new " + item + ".");
        }
        allocated.add(item);
    }
    else if (this.callback.isStale(item)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Received a stale item " + item + ", will attempt to get a new one.");
        }
        doRemoveItem(item);
        item = doGetItem();
    }
    this.inUse.add(item);
    return item;
}
请参考他们的源代码了解更多信息