Reading XLSX throws OutOfMemoryError PermGen-Collection of common programming errors
At the start of my readXlsx
method this line throws a PermGen Error
:
XSSFWorkbook wb = new XSSFWorkbook(OPCPackage.open(is));
where is
is an InputStream
for an Excel file sent over HTTP Post.
Trying to upload a few times with this error caused tomcat to crash. The file sent wasn’t bigger then 0,05 MB either.
Any idea what can cause this?
I see that I never close the InputStream
, can this cause this?
Edit: It’s actually an POIXMLException at the line that declares XSSFWorkbook, caused by PermGen Error
StackTrace: org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:403)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:186)
at classes.XLSXReader.readXLSX(XLSXReader.java:23)
at trainweb.ParticipantUploader.uploadCourseParticipants(ParticipantUploader.java:204)
at trainweb.ParticipantUploader.doPost(ParticipantUploader.java:139)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60)
... 23 more
Caused by: java.lang.OutOfMemoryError: PermGen space
at java.lang.String.intern(Native Method)
at org.apache.xmlbeans.impl.piccolo.util.CharStringConverter.convert(CharStringConverter.java:110)
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.yytext2(PiccoloLexer.java:3319)
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseElementNameNS(PiccoloLexer.java:2360)
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseOpenTagNS(PiccoloLexer.java:1455)
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseTagNS(PiccoloLexer.java:1362)
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.yylex(PiccoloLexer.java:4678)
at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.yylex(Piccolo.java:1290)
at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.yyparse(Piccolo.java:1400)
at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.parse(Piccolo.java:714)
at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3439)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1270)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1257)
at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
at org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(Unknown Source)
at org.apache.poi.xssf.model.ThemesTable.(ThemesTable.java:44)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.Native
-
PermGen means that you have exhausted the space for new Java classes in your JVM. Probably you’re already close to the limit and as soon as you try to use a big library for the first time, it can’t load all the classes it needs.
You should raise the limit, passing -XX:MaxPermSize=… to the JVM, for example -XX:MaxPermSize=128m.
-
When running in a environment like an application server or web server it is likely that the number of classes loaded is too high. Therefore please increase your PermSize when you run in an application server (or web application server like Tomcat).
To do this append
-XX:MaxPermSize=...m
to the java command starting your server. Please read the server documentation how to append additional parameters.The given parameter can be different if the used JRE is not the one from Oracle.