0

在我的readXlsx方法开始时,这一行抛出一个PermGen Error

XSSFWorkbook wb = new XSSFWorkbook(OPCPackage.open(is));

哪里isInputStream通过 HTTP Post 发送的 Excel 文件。

尝试使用此错误上传几次导致 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
4

2 回答 2

0

在应用程序服务器或 Web 服务器等环境中运行时,加载的类的数量可能过多。因此,当您在应用程序服务器(或像 Tomcat 之类的 Web 应用程序服务器)中运行时,请增加您的 PermSize。

为此,请附加-XX:MaxPermSize=...m到启动服务器的 java 命令。请阅读服务器文档如何附加其他参数。

如果使用的 JRE 不是来自 Oracle 的 JRE,则给定的参数可能不同。

于 2013-06-11T08:08:56.883 回答
0

PermGen 意味着您已经用尽了 JVM 中新 Java 类的空间。可能你已经接近极限了,一旦你第一次尝试使用一个大库,它就无法加载它需要的所有类。

您应该提高限制,将 -XX:MaxPermSize=... 传递给 JVM,例如 -XX:MaxPermSize=128m。

于 2013-06-11T08:02:56.750 回答