0

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.<init>(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.<init>(ThemesTable.java:44) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.Native
sjallamander
  • 439
  • 2
  • 6
  • 20
  • Does `OPCPackage.open(is)` or `new XSSFWorkbook(...)` cause the error? If you know that you may have a look at the documentation if there are some hints why you are running out of memory. – tbraun89 Jun 11 '13 at 07:58
  • Can you please tell us the environment you use for execution e.g. application server or standalone application? – Uwe Plonus Jun 11 '13 at 07:59
  • @UwePlonus the application is running on **Tomcat**. (from his question) – tbraun89 Jun 11 '13 at 08:06
  • 1
    You can use JVisualVM (bundled with the JDK) or similar to get some insights on what's going on. You will be able to see the PermGen usage and the number of classes loaded – Guillaume Jun 11 '13 at 08:24
  • Looking at the used PermGen in JVisualVM it seems that it gets bigger the first time i upload a Excel file. Maybe because it only need to load the classes one time? Should the used PermGen decrease back when it's done? cause it doesn't – sjallamander Jun 11 '13 at 08:43
  • It's also an PrintWriter that I have forgot to close. I hope closing the InputStream and PrintWriter will help. – sjallamander Jun 11 '13 at 08:59

2 Answers2

0

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.

Alessio Stalla
  • 1,022
  • 6
  • 22
  • 1
    I think this should not be the first thing to try. Before increasing the memory limit he should investigate why the error occurs. If there is no design error in the code and he realy needs more memory this will be the right option. – tbraun89 Jun 11 '13 at 08:12
0

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.

Uwe Plonus
  • 9,803
  • 4
  • 41
  • 48