apache poi - java.lang.OutOfMemoryError: Java heap space for 100000 records -
trying write excel file using following code
public static void main(string[] args) { xssfworkbook workbook = new xssfworkbook(); xssfsheet sheet = workbook.createsheet("book data"); map<string, object[]> data = new treemap<string, object[]>(); data.put("1", new object[] {"id", "name", "lastname"}); for(int i=2;i<100000;i++) { data.put(string.valueof(i), new object[] {i, "name"+i, "lastname"+i}); } set<string> keyset = data.keyset(); int rownum = 0; (string key : keyset) { row row = sheet.createrow(rownum++); object [] objarr = data.get(key); int cellnum = 0; (object obj : objarr) { cell cell = row.createcell(cellnum++); if(obj instanceof string) cell.setcellvalue((string)obj); else if(obj instanceof integer) cell.setcellvalue((integer)obj); } } try { fileoutputstream out = new fileoutputstream(new file("d:\\nameandlname.xlsx")); workbook.write(out); out.close(); system.out.println("nameandlname.xlsx written successfully."); } catch (exception e) { e.printstacktrace(); } } vm arguments -xms512m -xmx1024m
eclipse.ini:
-startup plugins/org.eclipse.equinox.launcher_1.1.0.v20100507.jar --launcher.library plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.1.r36x_v20100810 -product org.eclipse.epp.package.jee.product --launcher.defaultaction openfile --launcher.xxmaxpermsize 1024m -showsplash org.eclipse.platform --launcher.xxmaxpermsize 256m --launcher.defaultaction openfile -vmargs -dosgi.requiredjavaversion=1.5 -xms512m -xmx1024m -vm c:/program files (x86)/java/jdk1.6.0_21/bin/javaw.exe and error getting:
exception in thread "main" java.lang.outofmemoryerror: java heap space @ org.apache.xmlbeans.impl.store.saver$textsaver.resize(saver.java:1592) @ org.apache.xmlbeans.impl.store.saver$textsaver.preemit(saver.java:1223) @ org.apache.xmlbeans.impl.store.saver$textsaver.emit(saver.java:1144)
what need sxssf (streaming usermodel api).
sxssf (package: org.apache.poi.xssf.streaming) api-compatible streaming extension of xssf used when large spreadsheets have produced, , heap space limited.
there example on page too: need substitute xssfworkbook sxssfworkbook.
Comments
Post a Comment