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 掉
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.