在我的readXlsx
方法开始时,此行会抛出一个PermGen Error
:
XSSFWorkbook wb = new XSSFWorkbook(OPCPackage.open(is));
其中is
是通过HTTP Post发送的Excel文件的InputStream
。
尝试使用此错误上载几次导致tomcat崩溃。 发送的文件不大于 0,05 MB 。
知道是什么原因引起的吗?
我发现我从未关闭InputStream
,这会导致这个吗?
编辑:它实际上是声明XSSFWorkbook的行的POIXMLException,由PermGen错误导致
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
答案 0 :(得分:0)
PermGen意味着您已经耗尽了JVM中新Java类的空间。可能你已经接近极限了,一旦你第一次尝试使用一个大型库,它就无法加载它所需的所有类。
您应该提高限制,将-XX:MaxPermSize = ...传递给JVM,例如-XX:MaxPermSize = 128m。
答案 1 :(得分:0)
在应用程序服务器或Web服务器等环境中运行时,加载的类数可能太高。因此,请在应用程序服务器(或Tomcat等Web应用程序服务器)中运行时增加PermSize。
为此,请将-XX:MaxPermSize=...m
附加到启动服务器的java命令中。请阅读服务器文档,了解如何附加其他参数。
如果使用的JRE不是来自Oracle的JRE,则给定的参数可以不同。