资源泄漏:使用Apache.POI XSSFWorkbook时,工作簿永远不会被关闭 [英] Resource leak: workbook is never closed warning when using Apache.POI XSSFWorkbook

查看:5094
本文介绍了资源泄漏:使用Apache.POI XSSFWorkbook时,工作簿永远不会被关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我使用Apache POI将Excel文件解析为我的数据库。为此,我正在初始化 XSSFWorkbook ,如下所示:

So, I using Apache POI in order to parse an Excel file to my Database. For this I am initializing an XSSFWorkbook as follows:

XSSFWorkbook workbook = new XSSFWorkbook(fIP);

然后我继续我的方法。 workbook.close()不可用作以后关闭工作簿的方法。关于如何在任务完成后让垃圾收集进入工作簿的任何想法?

Then I proceed with my method. workbook.close() is not available as a method to close the workbook afterwards. Any ideas of how can I let garbage collection take the workbook after the task is finished?

推荐答案

我有这个问题,它没什么意义。
最后我跟踪问题,我的IDE(netbeans)正在拿起早期版本的POI库(v3.8),它没有关闭方法。
因此,请检查您的类路径,并查找不同版本的POI库的重复导入。

I had this issue, and it was making little sense. In the end I tracked the issue down to my IDE (netbeans) was picking up an earlier version of the POI libraries (v3.8) which didn't have the "close" method. So check your class path and look for duplicate imports of different versions of the POI libraries.

这篇关于资源泄漏:使用Apache.POI XSSFWorkbook时,工作簿永远不会被关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆