gpt4 book ai didi

java - 编码大型附件时出现内存不足错误

转载 作者:行者123 更新时间:2023-11-29 06:13:50 25 4
gpt4 key购买 nike

我在服务器端使用带有 AxiomSoapmessageFactory 的 spring ws:

<bean id="messageFactory" class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory">
<property name="payloadCaching" value="true"/>
<!-- Need to figure out the appropriate directory -->
<property name="attachmentCacheDir" value="..."/>
</bean>

当服务正在接收消息时,这工作正常。但是,当服务尝试提供大消息时,我得到 Java 内存不足异常。这是堆栈跟踪:

java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2786)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:94)
at org.apache.axiom.mime.impl.axiom.MultipartWriterImpl$PartOutputStream.write(MultipartWriterImpl.java:42)
at javax.activation.DataHandler.writeTo(DataHandler.java:294)
at org.apache.axiom.mime.impl.axiom.MultipartWriterImpl.writePart(MultipartWriterImpl.java:116)
at org.apache.axiom.om.impl.OMMultipartWriter.writePart(OMMultipartWriter.java:136)
at org.apache.axiom.om.impl.MIMEOutputUtils.writeSOAPWithAttachmentsMessage(MIMEOutputUtils.java:269)
at org.springframework.ws.soap.axiom.AxiomSoapMessage.writeSwAMessage(AxiomSoapMessage.java:298)
at org.springframework.ws.soap.axiom.AxiomSoapMessage.writeTo(AxiomSoapMessage.java:248)
at org.springframework.ws.server.MessageDispatcher.getMessageContent(MessageDispatcher.java:192)
at org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:174)
at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:88)
at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:57)
at org.springframework.ws.transport.http.ErrorAwareWebServiceMessageReceiverHandlerAdapter.handle(ErrorAwareWebServiceMessageReceiverHandlerAdapter.java:42)
at org.springframework.ws.transport.http.MessageDispatcherServlet2.doService(MessageDispatcherServlet2.java:148)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
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:127)
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:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:680)

问题似乎是服务试图在写出之前将整个附件读入内存。有没有办法流式传输附件?

我在 OSX 10.6.7 上的 Tomcat 实例中运行它 java --version =

Java 版本“1.6.0_24”Java(TM) SE 运行时环境(build 1.6.0_24-b07-334-10M3326)Java HotSpot(TM) 64 位服务器 VM(内部版本 19.1-b02-334,混合模式)

最佳答案

您是否尝试过更改以下参数以允许更多内存?

-Xms512m-Xmx1024m-XX:PermSize=256m

关于java - 编码大型附件时出现内存不足错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5825846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com