[alibaba/easyexcel]长时间使用会产生大内存对象 DeleteOnExitHook

2023-12-17 350 views
6

FileUtil 使用的是 DefaultTempFileCreationStrategy

    public static void createPoiFilesDirectory() {
        File poiFilesPathFile = new File(poiFilesPath);
        createDirectory(poiFilesPathFile);
        TempFile.setTempFileCreationStrategy(new DefaultTempFileCreationStrategy(poiFilesPathFile));
        poiFilesPathFile.deleteOnExit();
    }

但是 DefaultTempFileCreationStrategy 的删除策略是 deleteOnExit,对于服务端程序来说,可能会造成java.io.DeleteOnExitHook 大对象,而且无法 GC 掉

image

TempFileCreationStrategy 的注释也表示:

DefaultTempFileCreationStrategy deletes temporary files when the JVM exits. This may not be suitable for long-running applications that never shut down the JVM since the list of registered files and disk space usage would grow for as long as the JVM is running. You may wish to implement your own strategy that meets the needs of your situation.

回答

5
image

可以看出,每当执行Excel相关操作时,这里就会增加

0

这个是个问题 已经在 3.1.2中修复

7

image 已经升级到3.1.3. 看起来似乎还是会增长 image

TempFile.setTempFileCreationStrategy(new DefaultTempFileCreationStrategy(poiFilesPathFile));之后,是不是有可能其他地方也会deleteOnExit

image

static这里还有,不清楚有没有关系