自动清理 tomcat 缓存 - 多部分文件临时上传

Auto clean up tomcat cache - Multipart file temp uploads

我有 Spring 引导应用程序,允许用户上传多部分文件,我将处理这些文件。我已经阅读了多部分文件的官方文档。

The uploaded multipart file contents are either stored in memory or temporarily on disk. In either case, the user is responsible for copying file contents to a session-level or persistent store as and if desired. The temporary storages will be cleared at the end of request processing.

这里的问题是 tomcat 运行 内存不足,其中 删除的临时文件保留在 var/cache/tomcat8/work/catalina/localhost/ROOT 文件夹中。

当我们重新启动apache 或重新启动机器时,那些删除的文件将被删除。但是如何从 tomcat 缓存中自动清理这些文件呢?为什么会发生?无论如何,首先要禁用存储这些临时多部分文件上传吗?

在代码中,有一些输入流没有正确关闭。在我的代码中关闭流后,问题得到解决