From 23e3be4ec1067cc3543cc415e730886a9acfc104 Mon Sep 17 00:00:00 2001 From: Looly Date: Tue, 16 Sep 2025 21:05:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D`JschSessionPool`=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E9=97=AE=E9=A2=98=EF=BC=88pr#4079@Github=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../src/main/java/cn/hutool/extra/ssh/JschSessionPool.java | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c3d9037c..efa905a95 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ * 【cron 】 修复`CronPatternUtil.nextDateAfter`当日为L时计算错误问题。(issue#4056@Github) * 【db 】 修复`NamedSql.replaceVar`关键字处理问题(issue#4062@Github) * 【db 】 修复`DialectRunner.count`方法中,去除包含多字段order by子句的SQL语句时错误问题(issue#4066@Github) +* 【extra 】 修复`JschSessionPool`并发问题(pr#4079@Github) ------------------------------------------------------------------------------------------------------------- # 5.8.40(2025-08-26) diff --git a/hutool-extra/src/main/java/cn/hutool/extra/ssh/JschSessionPool.java b/hutool-extra/src/main/java/cn/hutool/extra/ssh/JschSessionPool.java index ffcf99c7a..4d312c8ec 100755 --- a/hutool-extra/src/main/java/cn/hutool/extra/ssh/JschSessionPool.java +++ b/hutool-extra/src/main/java/cn/hutool/extra/ssh/JschSessionPool.java @@ -6,7 +6,6 @@ import com.jcraft.jsch.Session; import java.util.Iterator; import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; /** * Jsch会话池 @@ -14,12 +13,16 @@ import java.util.concurrent.ConcurrentHashMap; * @author looly */ public enum JschSessionPool { + + /** + * 单例对象 + */ INSTANCE; /** * SSH会话池,key:host,value:Session对象 */ - private final SimpleCache cache = new SimpleCache<>(new ConcurrentHashMap<>()); + private final SimpleCache cache = new SimpleCache<>(); /** * 获取Session,不存在返回null