1.线程是DestroyTask,方法是shrink

2.现在还未弄清楚疑问点,后续继续研究

1)配置淘汰时间,不去判断哪些连接是否满足淘汰条件,直接把头部的几个放入淘汰数组

if (idleMillis >= minEvictableIdleTimeMillis) {
if (checkTime && i < checkCount) {
evictConnections[evictCount++] = connection;
continue;
} else if (idleMillis > maxEvictableIdleTimeMillis) {
evictConnections[evictCount++] = connection;
continue;
}
}

2)为啥把需要淘汰的连接先都移除掉,没有根据淘汰的数量去移除,然后再判断数量是否满足条件,不满足又去创建连接

            int removeCount = evictCount + keepAliveCount;
            if (removeCount > 0) {
                System.arraycopy(connections, removeCount, connections, 0, poolingCount - removeCount);
                Arrays.fill(connections, poolingCount - removeCount, poolingCount, null);
                poolingCount -= removeCount;
            }
            keepAliveCheckCount += keepAliveCount;

            if (keepAlive && poolingCount + activeCount < minIdle) {
                needFill = true;
            }
if (needFill) {
lock.lock();
try {
int fillCount = minIdle - (activeCount + poolingCount + createTaskCount);
for (int i = 0; i < fillCount; ++i) {
emptySignal();
}
} finally {
lock.unlock();
}
} else if (onFatalError || fatalErrorIncrement > 0) {
lock.lock();
try {
emptySignal();
} finally {
lock.unlock();
}
}
 

 

posted on 2022-05-12 00:22  柳无情  阅读(287)  评论(0编辑  收藏  举报