From ae4d79ebd618e29e2f859fef210231bf105b7adf Mon Sep 17 00:00:00 2001 From: Looly Date: Tue, 21 Feb 2023 12:00:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DTailer=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E8=B7=9F=E9=9A=8F=E5=9C=A8=E8=B0=83=E7=94=A8?= =?UTF-8?q?stop=E5=90=8E=EF=BC=8C=E6=96=87=E4=BB=B6=E4=BE=9D=E6=97=A7?= =?UTF-8?q?=E8=A2=AB=E5=8D=A0=E7=94=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ .../src/main/java/cn/hutool/core/io/file/Tailer.java | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9cdf81a6..3f0675390 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ * 【core 】 修复FileUtil.rename报NoSuchFileException问题(pr#2894@Github) * 【core 】 修复StrUtil.split切分长度为0时的bug(pr#944@Gitee) * 【core 】 修复ReUtil.delAll方法当 content 仅为空格时的问题(issue#I6GIMT@Gitee) +* 【core 】 修复ReUtil.delAll方法当 content 仅为空格时的问题(issue#I6GIMT@Gitee) +* 【core 】 修复Tailer文件内容跟随在调用stop后,文件依旧被占用问题(issue#I6GFD2@Gitee) ------------------------------------------------------------------------------------------------------------- diff --git a/hutool-core/src/main/java/cn/hutool/core/io/file/Tailer.java b/hutool-core/src/main/java/cn/hutool/core/io/file/Tailer.java index bc4305c40..2fff9a90f 100755 --- a/hutool-core/src/main/java/cn/hutool/core/io/file/Tailer.java +++ b/hutool-core/src/main/java/cn/hutool/core/io/file/Tailer.java @@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUnit; import cn.hutool.core.exceptions.UtilException; import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IORuntimeException; +import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.LineHandler; import cn.hutool.core.lang.Console; import cn.hutool.core.util.CharUtil; @@ -137,7 +138,11 @@ public class Tailer implements Serializable { * 结束,此方法需在异步模式或 */ public void stop(){ - this.executorService.shutdown(); + try{ + this.executorService.shutdown(); + }finally { + IoUtil.close(this.randomAccessFile); + } } // ---------------------------------------------------------------------------------------- Private method start