1.线程是DestroyTask,方法是shrink
![](https://img2022.cnblogs.com/blog/1365252/202205/1365252-20220512001505467-844003448.png)
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();
}
}