grails - OutOfMemoryError : Java heap space to upload 8 MB size file

标签 grails groovy out-of-memory apache-poi

我正在使用 Grails 2.4.4 并尝试使用“apache poi”插件上传 .xlsx 文件,但是当文件大小约为 8 MB 时,我收到 JAVA 堆大小异常。

我的 Controller 具有以下操作和方法:-

def uploadForm() {       
       String fileName = "D:\\File.xlsx"
       Map excelSheetMap = process(fileName)
}

Map process(String fileName) {
    ExcelBuilder excelBuilder = new ExcelBuilder(fileName)  
    //Getting JAVA Heap Size exception here when I am trying to create an object 
    //of ExcelBuilder with the file      
}

ExcelBuilder.groovy 类文件看起来像这样
class ExcelBuilder {
   Workbook workbook
   ExcelBuilder(String fileName) {      
      new File(fileName).withInputStream { is ->
         workbook = new XSSFWorkbook(is)
      }
   }
}

我也尝试过使用 grails-excel-import 插件,但我遇到了同样的异常。

有人可以建议如何在 grails 中导入大尺寸的 excel 文件。提前致谢。

最佳答案

Poi 确实有很高的内存占用。请参见:
http://poi.apache.org/spreadsheet/index.html

你可以试试 SXSSF。 SXSSF 是 XSSF 的 API 兼容流扩展,可在必须生成非常大的电子表格且堆空间有限时使用。

关于grails - OutOfMemoryError : Java heap space to upload 8 MB size file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31069185/

相关文章:

javascript - 在同一页面加载的 javaScript 文件中使用 gsp 布局声明变量

Grails,存储应用程序自己的设置(单域类?)

hibernate - Grails "a different object with the same identifier value was already associated with the session"错误

java - 多次打开文件时 Lucene 内存不足

android - 如何在Android中修复InvocationTargetException,OutOfMemoryError和IllegalStateException?

grails - 如何在 Config.groovy 中获取 Grails 应用程序名称?

jenkins - 从给定 Jenkins 计算键的映射中获取常规值?

groovy - 鸭子类型(duck typing)与静态类型相比有哪些优点?

android - "java.lang.OutOfMemoryError"在 Android 中新建一个 int 数组时

grails - 如何检测shiro是否允许uri或从uri中提取 Controller 名称